How would you store string data inside a .txt file, so you can request data from the .txt file that is already there, or store additional data?
Printable View
How would you store string data inside a .txt file, so you can request data from the .txt file that is already there, or store additional data?
That sounds very... generic. Have you learnt about what's in the <fstream> standard header?
Write the strings to the file, one per line would likely be best. When reading from the file, just store everything in a container of some sort, std::vector<std::string> for example.
You come up with a file format. For example, as mentioned by hk_mp5kpdw, each element of the vector could be on a single line. Then since your vector holds structs as elements, the members of the struct could be comma separated, or separated by pipes, or perhaps you have a fixed width to store them, etc.Quote:
But how do you "extract" the data of a vector to a text file; AND still be able to make the app recognize it, and edit it later on?
Actually, I would suggest using SQLite and coming up with a database schema instead of a custom file format, but that may be a little advanced at this point, unless you already have some knowledge of relational databases.
If you want to learn about file handling, then yes. What do you already know?Quote:
Using the simplest .txt storage methods is a good start point, no?
Thanks