开发者

How can I process several inputs at once using cin or getline(), while only pressing "Enter" once?

nodeType* buildSet()
{
   nodeType *first, *newNode, *last;
   first = NULL;

   int num = 0;
   string input = "";

   getline(cin,input);
   stringstream myStream(input);

   while(myStream >> num)
//   while(num != -999)   
   {      
      newNode = new nodeType;
      newNode->info = num;
      newNode->link = NULL;

      if(first == NULL)
      {
         first = newNode;
         last = newNode;
      }
      else
      {
         last->link = newNode;
         开发者_C百科last = newNode;
      }
         getline(cin,input);      
//       cin >> num;  
   }

   return first;
}


I fixed the problem by deleting the second "getline(cin, input)".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜