cout << "How many questions are there going to be on this exam?" << endl;
cout << ">>";
getline(cin, totalquestions);
Run Code Online (Sandbox Code Playgroud)
这段小代码来自我创建的类中的一个函数,我需要totalquestions成为一个int,以便它可以运行for循环并不断询问我提出的问题总数.
question q;
for(int i = 0; i < totalquestions; i++)
{
q.inputdata();
questions.push_back(q);
}
Run Code Online (Sandbox Code Playgroud)
这段代码在哪里发挥?有没有人有任何想法让这项工作?