Just trying a programming test for fun. It stipulates that I should read each word of a file, one by one.
It hints that I might want to use ifstream, but won't let me use std::string, so it looks like I have to use char*
In C I would read line by line & use strok() as I have multiple delimiters (white-space, quotes, brackets, etc).
What the most C++ way to do this - get the words one by one - without using std::string ?
First you must make sure that you have memory allocated for your string (this part would be handled automatically by
std::string). Then just use the normal input operator>>, as it will separate on whitespace.Don't forget to free the memory you allocate (also handled automatically by
std::string).Lesson to be learned: Use
charpointers for exercises like these, otherwise usestd::string.