#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错误:在此范围内未声明'constexpr'
5错误:预期为';'在“双”之前
7错误:预期为';'在“双”之前
15错误:在此范围内未声明“euro_to_dollar”
17错误:未在此范围内声明“yen_to_dollar”
我在做Bjarne Stroustrup的《编程:使用C++的原理和实践》(第二版)中的一个问题。我可以在这里看到我在做什么错。我正在尝试学习C++,所以我基本上是个初学者。我感谢帮助人员。
最佳答案
我不知道本地头文件中有什么
#include "std_lib_facilities.h"
代替这一点,我添加了以下代码行
#include<iostream>
using namespace std;
if (unit = 'e')
//进行分配应该更正如下
if(unit =='e'),//检查是否相等
由于相同的原因,
else if (unit ='y')
应该更正如下else if (unit =='y')
此外,您应该使用编译器选项
-std=c++11
进行编译
关于c++ - 编译C++错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30609771/