Let's say I have a file I'm reading that goes something like this :
#character posX posY //commentary line: explains what it represents
CharacterName1 50.0 0.0
CharacterName2 32.0 50.0
The goal here is to be able to read the posX et posY and convert them in my C++ program into 2 double variables x and y.
For now, all I'm able to do is to start reading the file and see if the line corresponds to an empty line or a commentary line. Then, if the reading line finds the corresponding character name, i should be able to to continue reading this line to get the posX and the posY, but I have no clue on how to do that. I don't know how to skip the blank and how to start reading the number and how to finish reading it to then convert it into double.
Any idea on how I should do that ?
I truly hope this is clear enough.
Thank you in advance.
Attempt example
void loadMap(std::string const& filepath) {
std::ifstream infile(filepath.c_str());
if(infile.fail()) {
std::cerr << "Error... " << std::endl;
} else { /opening occured correctly
while ( !infile.eof() ) {
std::string line;
std::getline(infile, line);
if ( (line[0] != '#') or (line.empty()) ) { //if line not comment or not empty
if( line.find("CharacterName1") ) {.......
Then I'm lost.