所以我从文件中读取并遇到了问题。 我从文件中读入一个int,下一行是一个字符串。当我将字符串存储到我的变量中时,我什么也得不到。我得到一个空白。我想知道是否有一种方法来刷新ifstream,以便我可以获得文件的下一行。
这就是我输入文件的方式:
std::ifstream fin(fileName.c_str());
if(fin.good()){
std::getline(fin, this->name);
fin >> this->weight;
fin.ignore(1, '\n'); //this was added after a user commented on how to fix it
std::getline(fin, this->city);
std::getline(fin, this->destination);