我正在使用 Code::Blocks 版本 16.01,我正在从 www.learncpp.com 的第 1.3a 课中学习。我的代码如下所示:
#include <iostream>
#include "stdafx.h"
int main()
{
std::cout << "Enter a number: "; // ask user for a number
int x = 0;
std::cin >> x; // read number from console and store it in x
std::cout << "You entered " << x << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
整个程序运行良好,但只有一个错误,那就是#include stdafx.h; 我收到标题中列出的错误。帮助和稍微清楚的解释对我来说会很好(我显然没有经验)。
stdafx.h 由 Visual Studio 的预编译头文件实现使用。如果你也没有使用 VS
将 stdafx.h 文件从 Visual Studio 项目文件夹复制到 Code::Blocks 项目文件夹并继续构建。
或者
如果您没有 Visual Studio 项目,请删除该#include "stdafx.h"行。如果您没有 stdafx.h ,那么其中就没有您需要的内容。如果赔率对您不利,编译器会很快让您知道。