C++ 简单的文件流测试

#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>

int main()
{
    using namespace std;

    ifstream inStream;
    ofstream outStream;

    inStream.open("infile.dat");
    if (inStream.fail()) {
        cout << "打开文件 infile.dat 失败" << endl;
        exit(1);
    }

    outStream.open("outfile.dat");
    if (outStream.fail()) {
        cout << "打开文件 outfile.dat 失败" << endl;
        exit(1);
    }

    int first, second, thrid;
    inStream >> first >> second >> thrid;
    outStream << first << endl << second << endl << thrid << endl;

    inStream.close();
    outStream.close(); 

    return 0;
}

输出:

C++ 简单的文件流测试

infile.dat

C++ 简单的文件流测试

outfile.dat

C++ 简单的文件流测试

上一篇:题解 P4308 【[CTSC2011]幸福路径】


下一篇:逆向思维yyds