编辑:多亏了一些帮助,我发现我只是漏掉了括号。问题解决了。
最近,Visual Studio在最简单但实际上并不错误的事情上给了我错误,正因为如此,我不能运行任何程序,这非常令人沮丧。我有一个运行在Windows 10上的Visual Studio Professional 2013 Update 5。让我举个例子。
当我编写程序时:
#include <iostream>
using namespace std;
int main
{
cout << "Hello World!" << endl;
return 0;
}我得到了错误:
main.cpp(6):错误C2143:语法错误:';‘前缺少'}’
main.cpp(8):错误返回:语法错误:‘C2059’
main.cpp(9):错误C2059:语法错误:'}‘
main.cpp(9):错误C2143:语法错误:'}‘之前缺少';’
此外,在cout上,IntelliSense给我的错误是“没有合适的从'std::basic_ostream...‘到'int’的转换函数存在”。在返回时,它会显示“错误:需要一个声明”。同样的错误也出现在最后一个括号中。
为什么我会得到所有这些无意义的错误,以及如何让它们不再出现,这样我才能运行程序?
(附注:我尝试过在使用和不使用"using namespace std“的情况下编写程序,但没有任何变化。)
发布于 2015-12-04 05:15:52
您缺少main中的括号
#include <iostream>
using namespace std;
int main()
^^
{
cout << "Hello World!" << endl;
return 0;
}https://stackoverflow.com/questions/34076266
复制相似问题