SOLVED

SOLVED
Last edited on
...
Last edited on
First: Why do you write to the file on 14, 16, and so on?
Second: Do not check for eof before you read the data (which may cause the eof)

And yes you can read the first part of the file because you know how many lines to expect, which is rowAmount. So change to
1
2
3
4
5
6
7
8
        std::string str;
        for(int i = 0; i < rowAmount && std::getline(OPENFILE, str); ++i)
        {
            std::stringstream stream(str);
 
            std::string value;
            while(std::getline(stream, value, '|'))
...
...
Last edited on
...
Last edited on
I enter "\n" into OPENFILE in order to make it skip to the next line.
No, the new line is already handle by the operator>>

Unfortunately the operator>> leaves the '\n' in the stream. Before you use getline you need to remove the '\n' form the stream. Use ignore for that:

http://www.cplusplus.com/reference/istream/istream/ignore/


I don't really understand how it could, but all right.
1
2
3
4
5
        while(!OPENFILE.eof()) // stream is not in eof state
        {
            std::string str, value;
            std::getline(OPENFILE, str); // getline sets the stream in the eof state
            std::stringstream stream(str); // due to the eof state str is not modified, but you process it regardless 


there's an extra endline at the end of the file; is there an easy way to fix this?
The best (robust) would be to ignore such extra line, but you may do this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	savefile << "\n";

	for (int rows = 0; rows < objectMap.size(); rows++)
	{
		savefile << "\n";

		for (int columns = 0; columns < objectMap[rows].size(); columns++)
		{
			if (columns > 0) { savefile << "_"; }

			savefile << objectMap[rows][columns];
		}

		savefile << "\n";
	}
...
Last edited on
Topic archived. No new replies allowed.