# include # include # include using namespace std; int main ( ) // // LONGEST_WORD2 is a program which reads string input until end-of-file. // // Strings correspond roughly to words. A line of text is interpreted as // a list of strings separated by blanks. Thus, this program can read a file // and report the length of the longest string of nonblanks. Of course, // this means punctuation and numbers will be included in the count. // { int length; int length_max; string w; string w_max; length_max = 0; w_max = ""; while ( true ) { cin >> w; if ( cin.eof ( ) ) { break; } length = w.length ( ); if ( length_max < length ) { length_max = length; w_max = w; } } cout << "Longest word is \"" << w_max << "\" which has length " << length_max << ".\n"; return 0; }