Hi. I have a c++ game where you make money throughout the game, and the game saves it to a separate txt file. When the game opens back up, it grabs the info in that txt file and puts it into a variable.

Thats not the problem though. I'm adding another feature where info needs to be saved on the second line of that file. Is there any way I can make the program just read a certain line of a file and get info from that?

Many thanks.

Recommended Answers

All 3 Replies

No -- text files have to be read sequentially from start to finish.

No -- text files have to be read sequentially from start to finish.

So what should I use?

You may read data from anyone line in the file.
But it's not working for writing. If your file is empty, y can write from begin to end. And if your file is not empty, y can add data in the end of file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.