How Do I Open A txt File Without It Erasing The Previous Content

前端 未结 2 1028
清酒与你
清酒与你 2020-12-12 02:00

So I want to be able to open up the file after the console closes and be able to continue adding to the file.

int main(){
    string inputWord;
    ofstream          


        
相关标签:
2条回答
  • 2020-12-12 02:23

    http://www.cplusplus.com/reference/fstream/fstream/open/

    at here there is an example also.

    // fstream::open / fstream::close
    #include <fstream>      // std::fstream
    
    int main () {
    
      std::fstream fs;
      fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);
    
      fs << " more lorem ipsum";
    
      fs.close();
    
      return 0;
    }
    
    0 讨论(0)
  • 2020-12-12 02:45

    You have to open the file stream in append mode:

    std::ofstream out("Info.txt", std::ios_base::app);
    //                            ^^^^^^^^^^^^^^^^^^
    
    0 讨论(0)
提交回复
热议问题