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?
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?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
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.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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
If you want to learn about file handling, then yes. What do you already know?Using the simplest .txt storage methods is a good start point, no?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks