我如何编译这个c++代码,它以" ':main'必须返回'int'结尾?(复制)

时间:2022-09-10 09:38:45

This question already has an answer here:

这个问题已经有了答案:

I have tried to find a solution that make batch file start flashing on taskbar and only good solution was this post on Stack Overflow.

我试图找到一个解决方案,使批处理文件开始在任务栏上闪烁,唯一好的解决方案是这个关于栈溢出的帖子。

But I can't compile the code with WinGW or anything else to EXE, only getting this error:

但是我不能用WinGW或其他任何代码来编译EXE,只能得到这个错误:

hello.cpp:6:32: error: '::main' must return 'int'

Right now, I'm using TDM-GCC to compile code, because it's bit better...

现在,我使用TDM-GCC来编译代码,因为它更好一些……

Can somebody give me code that actually works or even better compile it to EXE already?

有人能给我一些实际有效的代码吗?或者更好的把它编译成EXE ?

P.S. Even more better if somebody could compile this Delphi code, because I can't find any software that's free.

如果有人能编译这个Delphi代码会更好,因为我找不到任何免费的软件。

EDIT: I just go hell with it and downloaded Delphi trial and complied the delphi code and it worked! Sorry guys for bugging you unnecessarily :/ You can close this.

编辑:我只是去地狱,下载德尔福试用,并遵守德尔福代码,它工作!抱歉打扰你了:/你可以关闭这个。

1 个解决方案

#1


7  

It's actually int main(), and the end must return an integer (so make the last line above "}" return 0; (indicates a successful run, anything non-zero is otherwise).

它实际上是int main(),并且结尾必须返回一个整数(因此,将“}”上的最后一行返回0;(表示运行成功,否则任何非零值都是无效的)。

#include <iostream>
using namespace std;
int errors;

int main(arg stuff) {
    std::cout << "C++!";

    if (errors > 0)
         return 1;

    return 0;
}

#1


7  

It's actually int main(), and the end must return an integer (so make the last line above "}" return 0; (indicates a successful run, anything non-zero is otherwise).

它实际上是int main(),并且结尾必须返回一个整数(因此,将“}”上的最后一行返回0;(表示运行成功,否则任何非零值都是无效的)。

#include <iostream>
using namespace std;
int errors;

int main(arg stuff) {
    std::cout << "C++!";

    if (errors > 0)
         return 1;

    return 0;
}