0

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
Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
user3087006
  • 9
  • 1
  • 1

1 Answers1

2
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);
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055