Is there some way to read consecutive words separated by spaces as strings until end of line is found in C++? To be precise, I'm working on an algorithmic problem and the input goes like:
some_word1 some_word2 some_word3 (...) some_wordn
other_data
And the trick is I don't know how many words will there be in the first line, just that I should read them as separate words for further processing. I know I could use getline()
, but after that I'd have to work char-by-char to write each word in a new string when space occurs. Not that it's a lot of work, I'm just curious if there's a better way of doing this.