clear data inside text file in c++

前端 未结 4 873
借酒劲吻你
借酒劲吻你 2020-12-14 00:08

I am programming on C++. In my code I create a text file, write data to the file and reading from the file using stream, after I finish the sequence I desire I wish to clear

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 00:33

    As far as I am aware, simply opening the file in write mode without append mode will erase the contents of the file.

    ofstream file("filename.txt"); // Without append
    ofstream file("filename.txt", ios::app); // with append
    

    The first one will place the position bit at the beginning erasing all contents while the second version will place the position bit at the end-of-file bit and write from there.

提交回复
热议问题