我试图在一个文件中打印出 3 行,但最终发生的是它在所有 3 个位置打印 1 行,在所有三个位置打印第二行,然后,好吧,你猜对了,与第 3 个。我希望它只需按一下按钮就可以打印出所有 3 行。
ifstream read_file;
string fname, name;
cout << "Type the complete address of the file you would like to open.\n";
cin >> fname;
system("cls");
read_file.open(fname.c_str());
while(getline(read_file, fname))
{
if (fname == "")continue;
cout << "You had "<< fname << " health left\n";
cout << "You delt " << fname << " damage\n";
cout << "There were " << fname << " enemies left\n";
system("pause");
}
read_file.close();
system("pause");