C++ ((代码::块))-致命错误:stdafx.h:没有这样的文件或目录

C++ ((代码::块))-致命错误:stdafx.h:没有这样的文件或目录,c++,codeblocks,C++,Codeblocks,我正在使用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 fro

我正在使用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;
}
#包括
#包括“stdafx.h”
int main()
{
std::cout>x;//从控制台读取数字并将其存储在x中
std::cout您可以删除
#包括“stdafx.h”


我们在visual studio中使用:)。

stdafx.h由visual studio的预编译头实现使用。如果您不使用VS

将stdafx.h文件从VisualStudio项目文件夹复制到Code::Blocks项目文件夹中,然后继续生成


如果您没有Visual Studio项目,请删除
#include“stdafx.h”
liine。如果您没有stdafx.h,则很有可能其中没有您需要的内容。如果可能性对您不利,编译器会很快让您知道。

删除该行时会发生什么?只需删除
#include“stdafx.h”
。不要使用
stdafx.h
,除非您有很多未更改的include文件。对于大多数较小的项目,预编译头不会节省生成时间。如果更改了一个头文件,则必须重新编译预编译头文件。不总是这样。您可以拥有一个没有预编译头的项目,那么您将得到相同的错误:)很好的dyziok122.+1
#include "stdafx.h"