小编Sco*_*ott的帖子

试图在getline中使用int

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)

这段代码在哪里发挥?有没有人有任何想法让这项工作?

c++ string int getline

4
推荐指数
3
解决办法
5万
查看次数

标签 统计

c++ ×1

getline ×1

int ×1

string ×1