gpt4 book ai didi

c++ - 代码块运行错误: Build failed

转载 作者:太空宇宙 更新时间:2023-11-04 13:06:59 24 4
gpt4 key购买 nike

我是 C++ 新手,现在使用代码块(版本:codeblocks-16.01mingw-setup.exe)学习它。我的测试代码如下:

#include<iostream>
#include<stdlib.h>

int main()
{
int sum = 0, val = 1;
// keep executing the until val is greater than 10

while (val <=10 ) {
sum += val; // short-cut assignment
++val; // add 1 to val
}
std::cout << "Sum of 1 to 10 inclusive is "
<< sum << std::endl;
system("pause");
return 0;
}

这些代码写在一个名为 ex1.cpp 的空文件中。然后我通过单击“构建并运行”进行测试。结果又弹出一个文件main.cpp(这个不是我写的):

#include <iostream>
using namespace std;

int main()
{
cout << "Hello world!" << endl;
return 0;
}

附上屏幕截图以便您更好地检查:

enter image description here

最佳答案

你得到这个错误的原因是因为你的编译器设置不正确。你需要确保你使用的是 GNU GCC MinGW Compailer。转到 Settings-->Compiler 并确保每件事都和上面的一样截屏。 enter image description here

解决常见的代码块问题:Link

关于c++ - 代码块运行错误: Build failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41768544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com