I've been trying to make a program which requires me to read symbols until a new line. I saw a lot of people suggested getline()
in similar problems, but
I want to know if there is any other way to do it, mainly because of the way my code works so far.
#include <iostream>
#include <string>
int main()
{
std::string str;
while(true)
{
std::cin >> str;
std::cout << str << " ";
//some actions with token
}
}
The thing I find interesting about this code is that it first reads all the inputs, and then when I press Enter, it writes them all, for example, if I input
1 2 3 a b c
I get the output after I press enter. So is there a way to use that to my advantage and only take one line of input?