Vote count:
0
I have 3 functions that use getline. The first function checks which of the 2 functions to call depending on the first character of a line.
iMessage* getMessage(std::ifstream& ifs, char n) {
iMessage* msg;
std::string line;
std::getline(ifs, line, n);
if (line[0] == 'T') {
msg = new Twitter(ifs, n);
}
else if (line[0] == 'e') {
msg = new eMail(ifs, n);
}
else msg = nullptr;
return msg;
}
And in the twitter / email constructors:
eMail::eMail(std::ifstream& ifs, char n) {
std::string a;
std::getline(ifs, a, n);
//do stuff
}
Twitter::Twitter(std::ifstream& ifs, char n) {
std::string a;
std::getline(ifs, a, n);
//do stuff
}
The problem is that the constructors are always reading the first line of the file. How do I make it so the constructors are reading the same line as the getMessage() function?
asked 31 secs ago
Make getline() read the right line
Aucun commentaire:
Enregistrer un commentaire