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)".
精彩评论