Writing a string to the end of a file (C++)

后端 未结 4 2224
逝去的感伤
逝去的感伤 2021-02-12 16:06

I have a program already formed that has a string that I want to stream to the end of an existing text file. All of what little I have is this: (C++)

 void main(         


        
4条回答
  •  無奈伤痛
    2021-02-12 16:37

    Open your file using std::ios::app

     #include 
    
     std::ofstream out;
    
     // std::ios::app is the open mode "append" meaning
     // new data will be written to the end of the file.
     out.open("myfile.txt", std::ios::app);
    
     std::string str = "I am here.";
     out << str;
    

提交回复
热议问题