[Cs3] string tokenizing

Mikhail Nesterenko mikhail at cs.kent.edu
Tue Jul 7 14:37:45 EDT 2015


CS3 students,

reading or analyzing strings character by character to break them into
words is inefficient and is bad style. You can certainly use an
extraction operator to read the text word by word directly from the
file.

However, if you must use getline() to read the file line by line. You
can assign a string stream to the resultant line and process this
string similarly to the file. Here is example code

 http://vega.cs.kent.edu/~mikhail/classes/cs3/Labs/tokenize.cpp

That reads this file

  http://vega.cs.kent.edu/~mikhail/classes/cs3/Labs/test.txt

and prints it word by word.

Thanks,
-- 
Mikhail


More information about the cs3 mailing list