The thing is, I need to save the data in the file, so that it is not overwritten again, but added to the variable that has it again. For example: The program has a condition where you need to count the points of the players, and add to the already existing ones.

  • Read existing data, update, overwrite the file again (or use binary and write to the old place). - Harry
  • 2
    Possible duplicate question: Serialization in C ++ - VTT
  • @VTT is not a duplicate. Here a question about a simple dozapis, without serialization - Kromster

1 answer 1

You can open the file using fstream with the std::ios_base::app flag

The primitive example is how many times it runs, so many lines in the file.

 #include <iostream> #include <fstream> int main() { std::fstream testfile("e:\\test.txt", std::ios_base::app); testfile << "test" << std::endl; }