Jump to content
  • Advertisement
Sign in to follow this  
marltoro

File iostream question

This topic is 2650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am creating a program that will load data from a .dat file to multiple vectors inside the program.

But my question is, when I'm reading from a file, what would be the easiest way for me to skip lines or go to the previous line? I tried looking on Google but I couldn't get anything from there to work.

Share this post


Link to post
Share on other sites
Advertisement
The easiest way would be to parse the entire file into a data structure, then access that data structure instead of the file.

Share this post


Link to post
Share on other sites

I am creating a program that will load data from a .dat file to multiple vectors inside the program.

But my question is, when I'm reading from a file, what would be the easiest way for me to skip lines or go to the previous line? I tried looking on Google but I couldn't get anything from there to work.


Have you considered using ofstream and ifstream?
I used to use iostream, but I have found reinterpret_cast<char *> of my data struct makes for really slick saving and loading of game data, I could post some code on how I do it if your interested.

Share this post


Link to post
Share on other sites

Have you considered using ofstream and ifstream?
I used to use iostream, but I have found reinterpret_cast<char *> of my data struct makes for really slick saving and loading of game data, I could post some code on how I do it if your interested.
[/quote]

That would be great

Share this post


Link to post
Share on other sites
Files with a ".dat" extension usually contain non-text data, and thus the concept of skipping lines makes no sense.

Typically such files will have some metadata information in header, which will allows you to quickly determine the range of bytes you are interested in. Your file access API will provide a seek() function (or similar), which you can use to skip the intervening data.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!