In: Computer Science
c++
How do I get numbers and words before I press the enter?
For example, if i type cat 12 Rabbit 27 and then click enter, i want to stop receiving input.
Answer:
To read a single line at once you can use the function getline() in C++.
The use of getline() is demonstrated below.
Sample outputs:
If you want to take inputs and store them as words and numbers separately then you can use two arrays and use for loop to take the input for 'n' numbers of data.
Sample outputs:
I hope i answered your question. Please ask any doubts in comments and rate the answer after your doubts are cleared.