c_cpp FileIO C ++

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp FileIO C ++相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
    string line;
    //create an output stream to write to the file
    //append the new lines to the end of the file
    ofstream myfileI ("input.txt", ios::app);
    if (myfileI.is_open())
    {
        myfileI << "\nI am adding a line.\n";
        myfileI << "I am adding another line.\n";
        myfileI.close();
    }
    else cout << "Unable to open file for writing";
  
    //create an input stream to write to the file
    ifstream myfileO ("input.txt");
    if (myfileO.is_open())
    {
        while ( getline (myfileO,line) )
        {
            cout << line << '\n';
        }
        myfileO.close();
    }
    
    else cout << "Unable to open file for reading";
    
    return 0;
}

以上是关于c_cpp FileIO C ++的主要内容,如果未能解决你的问题,请参考以下文章

C语言项目编译

C++ FileIO Copy -VS- System("cp file1.x file2.x)

FileIO工具类

python 读写文件 FileIO

乐字节Java之fileIO流基础知识和操作步骤

QtConcurrent 给出错误