提问人:Keane Ho 提问时间:10/26/2023 最后编辑:user4581301Keane Ho 更新时间:10/26/2023 访问量:39
Cin 在一次输入后被忽略
Cin is being ignored after one input
问:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
const string FILE_NAME = "StudentData.txt";
string myData;
ofstream outfile("StudentData.txt");
cout << "What is your full name? \n";
cin >> myData;
outfile << myData << '\n';
cout << "Please Enter Street 1 \n";
cin >> myData;
outfile << myData << '\n';
cout << "test";
return 0;
}
在此代码中,我尝试使用 cin 获取> 1 个变量,但代码似乎跳过了输入请求并只是运行它。
我已经看过了,看到我应该使用 cin.ignore(),但我不知道如何应用它。
答: 暂无答案
评论