C++ fstream错误

WoW*_*WoW 1 c++ file-io

我学习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;
    }
Run Code Online (Sandbox Code Playgroud)

获取错误

Cannot open include file: 'fstream.h': No such file or directory
Run Code Online (Sandbox Code Playgroud)

怎么了?

Yuv*_*dam 7

将您的包含更改为:

#include <fstream>
Run Code Online (Sandbox Code Playgroud)

它是一个标准库,您尝试将其指向不存在的头文件.