cout << "How many questions are there going to be on this exam?" << endl;
cout << ">>";
getline(cin, totalquestions);
这段小代码来自我创建的类中的一个函数,我需要totalquestions
是一个 int ,这样它就可以运行 for 循环并不断询问我提出的问题总数。
question q;
for(int i = 0; i < totalquestions; i++)
{
q.inputdata();
questions.push_back(q);
}
这段代码在哪里发挥作用?有谁有办法让这项工作成功吗?
Use
cin >> totalquestions;
也检查一下错误
if (!(cin >> totalquestions))
{
// handle error
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)