我正在尝试编写一个程序,它将读取我的文本文件的第一行,然后将该数字输入到一个int变量中。但我很困惑,因为如何去做。从.txt文件读取一行并插入变量
int highscore; // Starting highscore
ifstream myfile ("highscore.txt");
if (myfile.is_open())
{
while (myfile.good())
{
getline(myfile,highscore);
cout << highscore << endl;
}
myfile.close();
}
但由于某种原因我得到错误。 |25|error: no matching function for call to 'getline(std::ifstream&, int&)'|
使用std :: getline intead – billz
什么是std :: for? – mystycs
找到getline函数的命名空间,就像你的std :: ifstream – billz