c++ - 编译C++错误

标签 c++ compiler-errors

#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/

相关文章:

c++ - Qt 将 slider 连接到双旋转框

c++ - char* 类型的值不能用于初始化 “char” 类型的实体

compiler-errors - 为什么有些错误会保持沉默?

Go 编译器未定义的方法

c++ - 使用 CMake 编译带有链接 dll 的应用程序。需要查看工作示例

c++ - OpenCV Unresolved 带有 objdetect.hpp 函数的外部错误 (C++)

c++ - 调用 pIBidiSpl2::SendRecvXMLString 时出错

c++ - AVX 类型的 C++ 内部函数的引用和在线资源

c - 如何在 Ubuntu 上解决错误消息 "gcc‬: command not found"(仅带参数)

java - Unresolved 编译问题: The method parseInt(String) is undefined for the type Integer