Reputation: 9
map - is a file that I opened. line - string
The upper part works, but the lower part does not.
getline(map, line);
getline(ssvalues, values, '|'); // Gets the name of the tileset file
tileset.loadFromFile(values.c_str());
getline(ssvalues, values, ' '); // Gets the size of the tile
tileSize = atoi(values.c_str());
getline(map, line); // Reads the next line.
ssvalues.str(line);
values = "";
// FROM HERE IT DOESNT WORK, 'values' always empty, why--
getline(ssvalues, values, '|'); // Get the X size of map
std::cout<<values;
mapSize.x = atoi(values.c_str());
getline(ssvalues, values, ' '); // Get the Y size of map
mapSize.y = atoi(values.c_str());
std::cout<<values;
The content of the file that I'm reading is:
tileset.png|32
1200|1200
Upvotes: 0
Views: 155
Reputation: 385405
ssvalues.str(line);
Here you reset the "contents" of the stringstream's buffer, but you didn't clear its error flags. Since it already hit EOF, this flag is still set and future getline
calls will fail.
You should add error checking into your code for all these input operations, and write the following instead of the above:
ssvalues.clear();
ssvalues.str(line);
Upvotes: 2