ofstream和ifstream

 ofstream(输出流)是从内存到硬盘,ifstream(输入流)是从硬盘到内存。
//#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ifstream in;
    ofstream out;
    in.open("a.txt");
    out.open("b.txt");
    int x, y, z;
    in >> x >> y >> z;
    out <<"x="<<x<<" "<<"y="<<y<<" "<<"z="<<z;
    //程序结束从一个文件获取输入或输出时,每个文件都应该关闭,关闭文件使流与文件断开
         in.close();
    out.close();
    return 0;
}


 
原文地址:https://www.cnblogs.com/hsy1941/p/8252764.html