I have done an exercise from "Thinking in C++" to print text from a file to the console one line at a time, with the user pressing enter to get the next line.
My original code is below, how could I change it for one word at a time?
I tried to alter my program to print one word at a time by changing "getline(in, word)" to "in >> word", but it prints each new word on a new line, the only input I have found to make the next word appear is Enter, I assume that's why.
Is there a way to make it print one word at a time when the user says, but on the same line?
Thanks for the reply, I don't think my question is clear. It is printing each word on a new line, I was wondering if you can print it on the same line. I will edit the post.
while (in.good())
{
in >> word; // get one word from the file
cout << word << " "; // print the word and a space so words don't merge
}
cout << endl; // finished printing, now go to a new line