2d tile map saver/loader

I am creating a 2d tile map game currently and I am trying to find a moderate way of saving and loading it through a text file and fstream.h. I am doing the saving by integers as well. What is difficult for me to understand is how integers save and load. Per line perhaps? I am just not sure about this.
Thank you
As long as you can tell where an integer begins and ends it doesn't matter. I recommend you write-up an example of what you'd like your file to look like and make your code read and write that.
How would I tell where an integer begins. I would not mind having an integer a line but I am using
My file>>integer; and i am not sure how it reads I.e. by line, separated by spaces, or some other way
The extraction operator successfully terminates (by default) on any whitespace or EOF.
It terminates with error if something went wrong.

For example, suppose your file had the following data:

3 
7 twelve 
94

You could read the first two integers with an:

1
2
3
int a, b, c;
f >> a >> b;
if (f) cout << "file is good.\n";

But if you try to read the next thing as an integer it will fail.

1
2
3
int c;
f >> c;
if (!f) cout << "file is bad.\";  

But, if you were to have read it as a string, it would have worked:

1
2
3
string c;
f >> c;
if (f) cout << "file is still good.\n";

And now you can get that last integer as usual:

1
2
int d;
f >> d;

Placement of newlines means nothing if you are just using the input extraction operators.

Did this answer your question? Or was there something more to it?
Topic archived. No new replies allowed.