简体   繁体   English

致命错误 C1083:无法打开包含文件:'fstream.h':没有这样的文件或目录

[英]fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory

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;我尝试使用命名空间 std; in the beginning of the code block, but I still received the error在代码块的开头,但我仍然收到错误

Your sample code is very, very old.您的示例代码非常非常古老。 Definitely previous century.绝对是上个世纪。 In this century, we use <fstream> .在本世纪,我们使用<fstream> The problem with <fstream.h> was that it's not standardized, so there are quite some possibilities about what it can contain. <fstream.h>的问题在于它没有标准化,因此它可以包含的内容有很多可能性。 The sample code you downloaded will have made some assumptions, and we can't guess.您下载的示例代码会做出一些假设,我们无法猜测。

In general, since we're talking about old code, it's going to predate namespace std;一般来说,由于我们谈论的是旧代码,它会早于namespace std; . . That is to say, there's likely no std::ifstream class but there could be an ifstream class.也就是说,可能没有std::ifstream类,但可能有一个ifstream类。 You've commented that using namespace std;您已经评论说using namespace std; didn't help, which is the normal hack to get ifstream working after including <fstream> .没有帮助,这是在包含<fstream>后让ifstream工作的正常黑客。 It seems you would need another hack, or newer sample code.看来您需要另一个 hack 或更新的示例代码。

Drop .h from <fstream.h> .<fstream.h>删除.h

Add using namespace std;添加using namespace std; below the included header files.在包含的头文件下面。

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.当您有一些代码使用 fstream 供编译器理解时,它需要标准库中 fstream 头文件中的声明等。 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) (注意:这个解释稍微简化了更多信息查找 C++ preprossesor)

All the imports are handled first.首先处理所有进口。 When the compiler can't find file fstream.h it stops.当编译器找不到文件 fstream.h 时,它会停止。 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.代码将(很可能)引用程序员期望在丢失文件中定义的名称。

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.当您更改 include 语句以包含正确的文件时,编译可以继续更仔细地查看您的代码。 From the comments I read that you get 'more errors'.从我读到的评论中,您会收到“更多错误”。 But the errors are in your code.但是错误在您的代码中。

As suggested try to fix them yourself.按照建议尝试自己修复它们。 After that create a new question on stackoverflow about specific errors that you don't understand.之后在 stackoverflow 上创建一个关于您不理解的特定错误的新问题。

I have done this eror.Do not need to remove or add anything else.Only you install turboo C++.我已经做了这个错误。不需要删除或添加任何其他东西。只有你安装turboo C++。 it code is turboo code.When i run it there is no eror to show me.它的代码是turboo 代码。当我运行它时,没有错误显示给我。 go to bin folder and copy past code and run it.转到 bin 文件夹并复制过去的代码并运行它。 Hope it will help to another.希望它会帮助另一个。

use gdb online compiler in that compiler select language as 'c++ turbo'在该编译gdb online compiler中使用gdb online compiler器选择语言为“c++ turbo”

[gdb compiler][1] [gdb 编译器][1]

hope it runs now :) [1]: https://www.onlinegdb.com/online_c++_compiler希望它现在运行:) [1]: https://www.onlinegdb.com/online_c++_compiler

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 严重错误C1083:无法打开包含文件:“ Item.h”&#39;:没有此类文件或目录 - fatal error C1083: Cannot open include file: 'Item.h”': No such file or directory 严重错误C1083:无法打开包含文件:&#39;mexutils.h&#39;:没有此类文件或目录 - fatal error C1083 : Cannot open include file: 'mexutils.h': No such file or directory 严重错误C1083:无法打开包含文件:&#39;vld.h&#39;:没有此类文件或目录 - fatal error C1083: Cannot open include file: 'vld.h': No such file or directory 致命错误 C1083:无法打开包含文件:“xyz.h”:没有这样的文件或目录? - fatal error C1083: Cannot open include file: 'xyz.h': No such file or directory? xxx.h:致命错误C1083:无法打开包含文件:&#39;yyyy.h&#39;:没有此类文件或目录 - xxx.h: fatal error C1083: Cannot open include file: 'yyyy.h': No such file or directory Visual Studio 2013:致命错误C1083:无法打开包含文件:&#39;winsock2.h&#39;:没有此类文件或目录 - Visual Studio 2013: fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory Microsoft Visual Studio Community 2019:致命错误 C1083:无法打开包含文件:'corecrt.h':没有这样的文件或目录 - Microsoft Visual Studio Community 2019: fatal error C1083: Cannot open include file: 'corecrt.h': No such file or directory SWIG致命错误C1083:无法打开包含文件 - SWIG Fatal error C1083: Cannot open include file QtCreator中的“致命错误C1083:无法打开包含文件” - “Fatal Error C1083: Cannot open include file” in QtCreator Qt-C ++-致命错误C1083:无法打开包含文件:&#39;afx.h&#39; - Qt - C++ - fatal error C1083: Cannot open include file: 'afx.h'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM