【问题标题】:C++ fstream errorC++ fstream 错误
【发布时间】:2009-02-15 15:08:12
【问题描述】:

我学习c++,今天开始学习文件处理。但运行此代码时出现错误

#include <iostream>
#include <fstream.h>

using namespace std;

    int main()
    {
        fstream file;
        file.open("test.txt",ios::in|ios::out)

        file.close();

        return 0;
    }

得到错误

Cannot open include file: 'fstream.h': No such file or directory

怎么了?

【问题讨论】:

    标签: c++ file-io


    【解决方案1】:

    将包含更改为:

    #include <fstream>
    

    它是一个标准库,你试图将它指向一个不存在的头文件。

    【讨论】:

      【解决方案2】:

      缺少分号:

       file.open("test.txt",ios::in|ios::out)
      

      应该是:

       file.open("test.txt",ios::in|ios::out);
      

      【讨论】:

        【解决方案3】:

        对于标准 C++ 包含,不要使用 .h 扩展名:

        #include <fstream>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-02-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多