我想在Codeblocks 20.03中运行以下代码,但收到错误消息:Undefined reference to 'WinMain@16'
。
码:
std::string countSheep(int number)
{
std::string res;
std::string s = " sheep...";
for (int i = 1; i <= number; i++) {
res += std::to_string(i) + s;
}
return res;
}
最初的问题是,我收到了错误消息:to_string'不是'std'的成员。之后,我将GCC编译器更新为9.2.0。但是现在,我不断收到该winmain错误消息。
你有什么想法,怎么办?
看一下:C ++对WinMain @ 16的未定义引用(代码:: Blocks)
而这:对WinMain @ 16的未定义引用-Codeblocks
同样关于您的代码,也许这里一些更有经验的c ++可能告诉我我错了。但是您的函数countSheep您什么都不返回,您正在尝试打印我认为的res?因此,您不会返回可在以后在var中使用的字符串,而只是打印出来。
如果是这样,并且正如我之前提到的,其他更有经验的人可以告诉我我对此有误,请尝试以下操作:
#include <iostream>
#include <string>
void countSheep(int number);
int main()
{
countSheep(3);
}
void countSheep(int number)
{
std::string res;
std::string s = " sheep...";
for (int i = 1; i <= number; i++)
{
res += std::to_string(i) + s;
std::cout << res << std::endl;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句