问题描述
(我使用Visual C ++ 2008)我一直听说main()是需要返回一个整数,但在这里我没有放在 return 0;
和它编译时带有0个错误和0个警告!在调试窗口中,它说程序已退出与代码0.如果这个函数命名任何东西除了main(),编译器抱怨说blah必须返回一个值。粘贴返回;
也会导致错误出现。
#include< iostream>
using namespace std;
int main()
{
cout< 嘿看看我应该返回一个int,但我不会!\\\
;
}
这可能是VC ++中的错误吗?
尝试查找C ++标准的在线副本,因此我可以引用此段落
(I'm using Visual C++ 2008) I've always heard that main() is required to return an integer, but here I didn't put in return 0;
and and it compiled with 0 errors and 0 warnings! In the debug window it says the program has exited with code 0. If this function is named anything other than main(), the compiler complains saying 'blah' must return a value. Sticking a return;
also causes the error to appear. But leaving it out completely, it compiles just fine.
#include <iostream>
using namespace std;
int main()
{
cout << "Hey look I'm supposed to return an int but I'm not gonna!\n";
}
Could this be a bug in VC++?
attempting to find an online copy of the C++ standard so I could quote this passage I found a blog post that quotes all the right bits better than I could.
这篇关于为什么int main(){}编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!