如何将用户输入推送到队列中?

时间:2013-11-14 21:06:55

标签: c++ queue

我无法弄清楚如何获取用户输入,并将其推送到我的队列中。我试着寻找例子但却找不到任何东西。这是我的一段代码:

queue<int> temp;

int Temperature::getTemp()
{
//excluded code
getline(myEngFile1, tempLine1); // assigns "what is temp?" to tempLine1
cout<<tempLine1<<"\n"; // What is the Temperature?
//cin>>value;
temp.push(value);
return value;
myEngFile1.close();
}

如何获取它以便我可以读取用户的输入并将其推送到我的队列中?

1 个答案:

答案 0 :(得分:0)

你可以这样做:

 int i;
 cout << "Enter a value to put in queue:";
 cin >> i;
 temp.push(i);

要输入多个值,您可以将其包装在循环中,直到用户输入一些无效值。

bool ok = true;
while(ok) {
  //get input like above
  //check if "i" is still ok
  //if ok the push on queue
  //else set ok to false
}
相关问题