Sign in to follow this  
marltoro

File iostream question

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
[quote name='Marltoro' timestamp='1302895446' post='4798886']
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.
[/quote]

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
[quote]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this