开发者

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

开发者 https://www.devze.com 2023-01-19 12:25 出处:网络
nodeType* buildSet() { nodeType *first, *newNode, *last; first = NULL; int num = 0; string input = \"\"; getline(cin,input);
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

精彩评论

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