SOLVED
Apr 28, 2014 at 6:51pm UTC
SOLVED
Last edited on May 1, 2014 at 4:24pm UTC
Apr 29, 2014 at 12:30pm UTC
...
Last edited on May 1, 2014 at 4:23pm UTC
Apr 29, 2014 at 1:12pm UTC
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, '|' ))
...
Apr 29, 2014 at 3:14pm UTC
...
Last edited on May 1, 2014 at 4:23pm UTC
Apr 29, 2014 at 7:59pm UTC
...
Last edited on May 1, 2014 at 4:23pm UTC
Apr 30, 2014 at 7:58am UTC
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" ;
}
Apr 30, 2014 at 8:09am UTC
...
Last edited on May 1, 2014 at 4:23pm UTC
Topic archived. No new replies allowed.