我无法循环浏览文本文件的内容,搜索数字然后找到,然后在数字存在的行上输出数据。
目前,无论您指定的是什么号码,它都会始终输出文本文件的第一行。
cout << endl << "Please enter a staff members ID: ";
cin >> id;
do
{
inStream.seekg(0, ios::beg);
getline(inStream, line);
if (line.find(id))
{
cout << endl << line;
}
else
{
cout << endl << "Error. Could not find the staff member.\n";
}
} while (id != id);
答案 0 :(得分:0)
将seekg行放在do while循环之外。 inStream.seekg(0,ios :: beg);
id!= id? : - )
如果您不想要无限循环,也会处于休息状态(EOF检查)。