+ 1

storing line of input and fetch it for later use

the user want to give a n number of inputs in one line, the program must read it and compare the data as given:: 5 // five numbers 2 3 1 4 5 //the data i tried getline() but the problem is that the data is separated by spaces so i used for loop (n+(n-1)) as terminating condition resulting in program that reads 10 as 1 and 0 separately i can't use this to compare process, need help!

14th Oct 2022, 11:26 PM
Max
Max - avatar
1 Resposta
+ 1
`getline` can take a third parameter for the delimiter. Try this: for(string line; getline(cin, line, ' ');) cout << stoi(line);
15th Oct 2022, 1:04 AM
Schindlabua
Schindlabua - avatar