C++ 致命错误 C1083:无法打开包含文件:'fstream.h':没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29162744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory
提问by Jethro Angelo
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"
嗨,我正在使用 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;在代码块的开头,但我仍然收到错误
回答by user092
Drop .h
from <fstream.h>
.
下降.h
从<fstream.h>
。
Add using namespace std;
below the included header files.
using namespace std;
在包含的头文件下面添加。
回答by MSalters
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>
. 问题<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.
一般来说,由于我们谈论的是旧代码,它会早于namespace std;
. 也就是说,可能没有std::ifstream
类,但可能有ifstream
类。你评论说using namespace std;
没有帮助,这是ifstream
在包含<fstream>
. 看来您需要另一个 hack 或更新的示例代码。
回答by Brainstorm
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 头文件中的声明等。告诉编译器获取它需要一个包含语句。(注意:这个解释稍微简化了更多信息查找 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 stackoverflow about specific errors that you don't understand.
按照建议尝试自己修复它们。之后在 stackoverflow 上创建一个关于您不理解的特定错误的新问题。
回答by Muhammad Mehdi
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 代码。当我运行它时,没有错误显示给我。转到 bin 文件夹并复制过去的代码并运行它。希望它会帮助另一个。