这是我第一次使用stackoverflow。我一直无法找到关于getline所需的信息。我是一个简单的工程转移编程类,所以我们编写的代码非常简单。我在这里尝试做的就是将用户定义的问题和答案放入两个不同的数组中。我的while循环看起来像这样(我正在使用for循环,但切换到只是为了看它是否会停止破坏):
int main ()
{
srand((unsigned)time(0));
string quest1[100], answ1[100];
int size1, x = 0, num, count1, visit[100], shuffle[100];
fstream flashcard1;
cout << "flashcard.cpp by NAME\n" << endl;
cout << "This program allows user to manipulate questions and answers for studying.\n" << endl;
cout << "\nHow many flash cards will be entered(MAX 100)? ";
cin >> size1;
cout << endl;
while(x < size1)
{
cout << "Enter Question: ";
getline(cin , quest1[x]);
cout << endl;
x = x++;
/*
cout << "Enter Answer: " << endl;
getline(cin,answ1[x]);
cout << endl;
flashcard1.open("flashcard1.dat", ios::app);
flashcard1 << quest1[x] << " " << answ1[x] << endl;
flashcard1.close();
cout << "Data Stored." << endl;
*/
}
}
我注意到输入部分的答案以及保存数据只是为了调试。当我运行程序时,它跳过第一个问题的getline,显示第二个循环“输入问题”,getline适用于其余的。因此,如果我的size1为5,则程序仅填充阵列位置1-4。请帮忙。 这是一个简单的闪存卡程序,可以像创建闪存卡一样研究和改组它们。