2015-06-03 288 views
-1
#include "std_lib_facilities.h" 

int main() 
{ 
constexpr double euro_to_dollar = 1.11; 
constexpr double yen_to_dollar = 0.0081; 
double dollar = 1.00; 

char unit= 'A'; 
cout <"Please enter a value followed by e or y: \n"; 
cin >>dollar>> unit; 
if (unit= 'e') 
cout << dollar << "Euro == " << euro_to_dollar*dollar << "dollar\n"; 
else if (unit='y') 
     cout << dollar << "Yen== " << yen_to_dollar * dollar << "dollar\n"; 
} 
 
5 error: 'constexpr' was not declared in this scope 
5 error: expected ';' before 'double' 
7 error: expected ';' before 'double' 
15 error: 'euro_to_dollar' was not declared in this scope 

17 error: 'yen_to_dollar' was not declared in this scope 

我做从编程的问题:原则和由Bjarne Stroustrup的练习使用C++(第二版)。我可以看到我在这里做错了什么。我试图学习C++,所以我基本上是一个初学者。我很感谢帮助的人。编译C++错误

+0

您正在使用什么编译器?它支持C++ 11吗? –

+0

'cout <“请输入一个值后跟e或y:\ n”;'应该是'cout <<' –

回答

1

constexpr关键字是在C++ 11中引入的,用-std=c++11进行编译。
实施例:

与克++:g++ main.cpp -o program.exe -std=c++11

与代码::块:
设置 - >编译器 - >编译器设置 - >编译器标志 - >勾选框Have g++ follow the C++ ISO C++ language standard - >确定


您还赋值给一个变量在你的if语句,与==取代:

if (unit= 'e') 
    //^

else if (unit='y') 
     // ^

而你错过了<在调用到std ::法院:

cout <"Please enter a value followed by e or y: \n"; 
//^
1

我不知道还有什么在你的本地头文件

#include "std_lib_facilities.h" 

代替我在代码中添加了以下几行代码

#include<iostream> 

using namespace std; 

if (unit = 'e') //做分配 应该纠正到如下

如果(单元== 'E'),//检查等于或不

else if (unit ='y')应该纠正到由于相同的原因

如下
else if (unit =='y') 

而且你应该编译使用编译器选项-std=c++11