If I had to read in a word from a document (one word at a time), and then pass that word into a function until I reach the end of the file, how would I do this?
What also must be kept in mind is that a word is any consecutive string of letters and the apostrophe ( so can't
or rojas'
is one word). Something like bad-day
should be two separate words, and something like to-be-husband
should be 3 separate words. I also need to ignore periods .
, semi-colons ;
, and pretty much anything that isn't part of a word. I have been reading it in using file >> s;
and then removing stuff from the string but it has gotten very complicated. Is there a way to store into s
only alphabet characters+apostrophes and stop at the end of a word (when a space occurs)?
while (!file.eof()) {
string s;
file >> s; //this is how I am currently reading it it
passToFunction(s);
}