Good evening everyone,
I'm trying to read from a text file source with the following format:
doomsday [villain]
Doomsday is a fictional supervillain appearing in American comic books published by DC Comics.
superman [hero]
Superman is a fictional superhero appearing in American comic books published by DC Comics.
These are two entries. I need to extract the name, role and description so I can place it into an object e.g.
DCCharacters newCharacter(characterName, characterRole, description);
My code so far:
ifstream fileToOpen(fileSrc);
if (fileToOpen.is_open()) {
string line;
string charName;
string charRole;
string charDesc;
while (!fileToOpen.eof()) {
getline(fileToOpen, line);
charName = line;
if (line == "") continue; // Skip blank lines
getline(fileToOpen, line);
charDescription = line;
if (line == "") continue;
DCCharacters newCharacter(characterName, characterRole, description);
this->DCCharsVector.push_back(newCharacter);
}
// Close the file
fileToOpen.close();
}
}
As you can see I can extract the character name and role in one line and the description in another, but I dont now how to seperate the name and role into two seperate variables to put them into the object like I need to.
I'm looking forward to any help.