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?
This is a discussion on Storing and accessing data from and to .txt files. within the C++ Programming forums, part of the General Programming Boards category; How would you store string data inside a .txt file, so you can request data from the .txt file that ...
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?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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.
I used to be an adventurer like you... then I took an arrow to the knee.
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.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Thanks