编译c++错误
Compile C++ error
#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 << "dollarn";
else if (unit='y')
cout << dollar << "Yen== " << yen_to_dollar * dollar << "dollarn";
}
<>之前没有在此范围内声明'constexpr'5 .错误:期望';'在'double'之前7 .错误:期望';'在'double'之前错误:'euro_to_dollar'未在此范围内声明在此范围内没有声明'yen_to_dollar'之前我正在做一个问题从编程:原理和实践使用c++(第二版)由Bjarne Stroustrup。我可以看到我做错了什么。我是一个尝试学习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++ 11中引入了constexpr
关键字,用-std=c++11
编译。
的例子:
with g++: g++ main.cpp -o program.exe -std=c++11
with code::blocks:
Settings -> Compiler -> Compiler Settings -> Compiler Flags ->选中Have g++ follow the C++ ISO C++ language standard
-> Ok
你也分配给一个变量在你的if语句,替换为==
:
if (unit= 'e')
// ^
和
else if (unit='y')
// ^
在调用std::cout:
时缺少<
cout <"Please enter a value followed by e or y: n";
// ^
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'