Can C++ process a notepad input file, by adding something without deleting all the previous context?

StackOverflow https://stackoverflow.com/questions/21864562

  •  13-10-2022
  •  | 
  •  

Domanda

For example, the notepad "n.in" contains : 1 2 3

I want to output : 1 2 3 4 5

but by adding 4 and 5 to the already created notepad and not just printing 1 2 3 4 5 from the beginning

The main idea is creating a "database" of accounts that any user can access and see for example all of his passwords which will be stored. Can anyone help?

//My first thought was saving the hole notepad content in a string an then outputting the string and afterwards the new, just received data (the new user creating an account) in a file with the same name, so that it will replace the first one. I think there could be a simpler solution provided with lower algorithm-complexity.

È stato utile?

Soluzione

What you are referring to are text files and not "notepads".

And what you want to do is append content which can be done by opening the file in the "append" mode like this :

std::fstream fs;
fs.open ("test.txt", std::fstream::out | std::fstream::app);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top