C++简单文件输入输出ofstream ifstream

头文件fstream包含了一个用于处理输出的ofstream类和一个处理输入的ifstream,可以声明对象并使用open()方法打开。

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ofstream outfile;
    outfile.open("out.txt");

    ifstream infile;
    infile.open("in.txt");

    //然后就可以像使用cin cout那样使用outfile和infile

    char logo[100];
    infile >> logo;
    outfile << logo;
}

在这里插入图片描述

不过我还是喜欢使用freopen

freopen("1.txt","r",stdin);
    freopen("2.txt","w",stdout);
发布了267 篇原创文章 · 获赞 38 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/dghcs18/article/details/104057157
今日推荐