一个使用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 Studio2017CommunityVCToolsMSVC14.16.27023include
C:Program Files (x86)Windows Kits10Include10.0.10240.0ucrt
但这样会产生以下错误:
D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(19): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(19): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(20): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(22): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(29): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(29): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(30): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecstdlib(32): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(17): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(17): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(18): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(23): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(30): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(30): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(31): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(33): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(40): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(40): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(41): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(43): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(50): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(50): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(51): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(53): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(60): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(60): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(61): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(63): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(71): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(71): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(72): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(74): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(81): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(81): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(82): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(84): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(91): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(91): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(92): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(94): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(101): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(101): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(102): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(104): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(111): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(111): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(112): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(114): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(121): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(121): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(122): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(124): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(132): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(132): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(133): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(135): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(142): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(142): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(143): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(145): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(152): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(152): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(153): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(155): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(162): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(162): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(163): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(165): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(172): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(172): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(173): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(175): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(182): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(182): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(183): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(185): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(192): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(192): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(193): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(195): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(202): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(202): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(203): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(205): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(212): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(212): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(213): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(215): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(222): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(222): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(223): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(225): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(233): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(233): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(234): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(236): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(244): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(244): error C2059: 语法错误:“;” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(245): error C2449: 在文件范围内找到“{”(是否缺少函数头?) D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(250): error C2059: 语法错误:“}” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(258): error C2061: 语法错误: 标识符“noexcept” D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023includecmath(258): fatal error C1003: 错误计数超过 100;正在停止编译
根据https://blog.csdn.net/dawang_789/article/details/108104838此文章的提示,是因为VS是C++,不是C,扩展名应当是cpp,把文件名改成cpp,就好了。