致命错误C1083:不能打开包含文件:'fstream。没有这样的文件或目录。

时间:2022-11-26 18:13:30

Hi I'm using visual C++ 2010 Express and I received that error when I compiled this sample program I downloaded "fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory"

Hi,我使用visual c++ 2010 Express,当我编译这个示例程序时,我收到了这个错误,我下载了“致命错误C1083:不能打开包含文件:fstream。h':没有这样的文件或目录"

#include<fstream.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>

and I tried putting in using namespace std; in the beginning of the code block, but I still received the error

我尝试使用命名空间std;在代码块的开头,但是我仍然收到错误。

4 个解决方案

#1


1  

Your sample code is very, very old. Definitely previous century. In this century, we use <fstream>. The problem with <fstream.h> was that it's not standardized, so there are quite some possibilities about what it can contain. The sample code you downloaded will have made some assumptions, and we can't guess.

您的示例代码非常非常古老。上个世纪。在这个世纪,我们使用 。的问题< fstream。h>是不标准化的,所以它包含的东西有很多可能性。您下载的示例代码会做出一些假设,我们无法猜测。

In general, since we're talking about old code, it's going to predate namespace std;. That is to say, there's likely no std::ifstream class but there could be an ifstream class. You've commented that using namespace std; didn't help, which is the normal hack to get ifstream working after including <fstream>. It seems you would need another hack, or newer sample code.

一般来说,由于我们讨论的是旧代码,所以它将提前命名空间std;也就是说,可能没有std::ifstream类,但是可能有一个ifstream类。您已经注释了使用名称空间std;没有帮助,这是在包括 之后,获得ifstream工作的正常方法。看起来您需要另一个hack,或者更新的样本代码。

#2


1  

Drop .h from <fstream.h>.

从< fstream.h > . h。

Add using namespace std; below the included header files.

添加使用名称空间性病;在包含的头文件下面。

#3


1  

Try without the '.h' at the end:

试没有”。h的最后:

#include <fstream>

Edit:

编辑:

It appears some further explanation is in order.

看来还有进一步的解释。

When you have some code that uses fstream for the compiler to understand what that code does it needs the declarations etc. from the fstream header file in the standard library. To tell the compiler to fetch that it needs an include statement. (Note: this explanation is slightly simplified for more info look up C++ preprossesor)

当您有一些代码使用fstream让编译器理解该代码是什么时,它需要来自标准库中的fstream头文件中的声明等等。告诉编译器获取它需要一个include语句。(注意:这个解释稍微简化了,因为更多的信息查找c++ preprossesor)

All the imports are handled first. When the compiler can't find file fstream.h it stops. Why? Because without a file that the programmer expects is necessary it is pointless to continue compiling the rest of the code. The code will (most likely) refer to names expected by the programmer to be defined in the missing file.

所有导入都是先处理的。当编译器找不到文件fstream时。h它停止。为什么?因为如果没有程序员期望的文件,那么继续编译其余的代码是没有意义的。代码(很可能)是指程序员希望在丢失的文件中定义的名称。

So when an included file is missing it is not looking any closer at the code you have written.

因此,当一个包含的文件丢失时,它不会在您所编写的代码中查找任何代码。

When you change the include statement to include the right file, the compilation can continue to look more closely at your code. From the comments I read that you get 'more errors'. But the errors are in your code.

当您更改include语句以包含正确的文件时,编译可以继续更仔细地查看您的代码。从我读到的评论中,你会得到更多的错误。但是错误在你的代码中。

As suggested try to fix them yourself. After that create a new question on * about specific errors that you don't understand.

正如建议试着自己修复它们。然后在*上创建一个关于特定错误的新问题,您不理解。

#4


0  

I have done this eror.Do not need to remove or add anything else.Only you install turboo C++. it code is turboo code.When i run it there is no eror to show me. go to bin folder and copy past code and run it. Hope it will help to another.

我已经做了这个。不需要删除或添加任何其他内容。只有安装了turboo c++。它的代码是turboo代码。当我运行它时,没有eror来显示我。转到bin文件夹并复制过去的代码并运行它。希望它能对另一个人有所帮助。

#1


1  

Your sample code is very, very old. Definitely previous century. In this century, we use <fstream>. The problem with <fstream.h> was that it's not standardized, so there are quite some possibilities about what it can contain. The sample code you downloaded will have made some assumptions, and we can't guess.

您的示例代码非常非常古老。上个世纪。在这个世纪,我们使用 。的问题< fstream。h>是不标准化的,所以它包含的东西有很多可能性。您下载的示例代码会做出一些假设,我们无法猜测。

In general, since we're talking about old code, it's going to predate namespace std;. That is to say, there's likely no std::ifstream class but there could be an ifstream class. You've commented that using namespace std; didn't help, which is the normal hack to get ifstream working after including <fstream>. It seems you would need another hack, or newer sample code.

一般来说,由于我们讨论的是旧代码,所以它将提前命名空间std;也就是说,可能没有std::ifstream类,但是可能有一个ifstream类。您已经注释了使用名称空间std;没有帮助,这是在包括 之后,获得ifstream工作的正常方法。看起来您需要另一个hack,或者更新的样本代码。

#2


1  

Drop .h from <fstream.h>.

从< fstream.h > . h。

Add using namespace std; below the included header files.

添加使用名称空间性病;在包含的头文件下面。

#3


1  

Try without the '.h' at the end:

试没有”。h的最后:

#include <fstream>

Edit:

编辑:

It appears some further explanation is in order.

看来还有进一步的解释。

When you have some code that uses fstream for the compiler to understand what that code does it needs the declarations etc. from the fstream header file in the standard library. To tell the compiler to fetch that it needs an include statement. (Note: this explanation is slightly simplified for more info look up C++ preprossesor)

当您有一些代码使用fstream让编译器理解该代码是什么时,它需要来自标准库中的fstream头文件中的声明等等。告诉编译器获取它需要一个include语句。(注意:这个解释稍微简化了,因为更多的信息查找c++ preprossesor)

All the imports are handled first. When the compiler can't find file fstream.h it stops. Why? Because without a file that the programmer expects is necessary it is pointless to continue compiling the rest of the code. The code will (most likely) refer to names expected by the programmer to be defined in the missing file.

所有导入都是先处理的。当编译器找不到文件fstream时。h它停止。为什么?因为如果没有程序员期望的文件,那么继续编译其余的代码是没有意义的。代码(很可能)是指程序员希望在丢失的文件中定义的名称。

So when an included file is missing it is not looking any closer at the code you have written.

因此,当一个包含的文件丢失时,它不会在您所编写的代码中查找任何代码。

When you change the include statement to include the right file, the compilation can continue to look more closely at your code. From the comments I read that you get 'more errors'. But the errors are in your code.

当您更改include语句以包含正确的文件时,编译可以继续更仔细地查看您的代码。从我读到的评论中,你会得到更多的错误。但是错误在你的代码中。

As suggested try to fix them yourself. After that create a new question on * about specific errors that you don't understand.

正如建议试着自己修复它们。然后在*上创建一个关于特定错误的新问题,您不理解。

#4


0  

I have done this eror.Do not need to remove or add anything else.Only you install turboo C++. it code is turboo code.When i run it there is no eror to show me. go to bin folder and copy past code and run it. Hope it will help to another.

我已经做了这个。不需要删除或添加任何其他内容。只有安装了turboo c++。它的代码是turboo代码。当我运行它时,没有eror来显示我。转到bin文件夹并复制过去的代码并运行它。希望它能对另一个人有所帮助。