《C++ Primer 中文版(第 5 版)》1.2

一个使用IO库的程序

#include "iostream"
#include "istream"
int main(){
    std::cout << "Enter two numbers:" << std::endl;
    int v1=0, v2=0;
    std::cin >> v1 >> v2;
    std::cout <<"The sum of" << v1 << " and " << v2
            <<" is " <<v1 +v2 <<std::endl;
    return 0;
}

 

因包含了<iostream>,报以下错误:

fatal error C1034: iostream: 不包括路径集

 

根据提示,应在环境变量中的系统变量中增加“include”项,以使代码能找到iostream,include的值为

D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include

C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt

《C++ Primer 中文版(第 5 版)》1.2

 

 

但这样会产生以下错误:

D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(19): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(19): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(20): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(22): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(29): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(29): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(30): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(32): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(17): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(17): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(18): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(23): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(30): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(30): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(31): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(33): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(40): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(40): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(41): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(43): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(50): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(50): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(51): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(53): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(60): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(60): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(61): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(63): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(71): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(71): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(72): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(74): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(81): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(81): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(82): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(84): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(91): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(91): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(92): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(94): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(101): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(101): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(102): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(104): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(111): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(111): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(112): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(114): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(121): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(121): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(122): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(124): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(132): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(132): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(133): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(135): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(142): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(142): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(143): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(145): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(152): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(152): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(153): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(155): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(162): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(162): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(163): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(165): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(172): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(172): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(173): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(175): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(182): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(182): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(183): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(185): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(192): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(192): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(193): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(195): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(202): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(202): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(203): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(205): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(212): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(212): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(213): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(215): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(222): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(222): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(223): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(225): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(233): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(233): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(234): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(236): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(244): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(244): error C2059: 语法错误:“;”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(245): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(250): error C2059: 语法错误:“}”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(258): error C2061: 语法错误: 标识符“noexcept”
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cmath(258): fatal error C1003: 错误计数超过 100;正在停止编译

 

根据https://blog.csdn.net/dawang_789/article/details/108104838此文章的提示,是因为VS是C++,不是C,扩展名应当是cpp,把文件名改成cpp,就好了。

 

上一篇:c primer plus 第二章编程练习——习题解答


下一篇:c++ primer复习(3)那些太容易被忽略的细节(持续更新)