////////////////////////////////////////////////////////////////// // // countlines.cpp // // This program reads input from cin, one line at a time, // counting the lines as it goes. When the input ends, // the program prints the number of lines. // // The program retrieves words from standard input (cin) // until reaching "end of file." You can run this // in two ways from a UNIX prompt: // // (1) countlines < someInputFileName // // (2) countlines // // In the second case, you will type the input. You // can type as many lines as you like. To terminate // the input, type CTRL-D at the start of a new line. // // Revision history: // 1/10/01 (Jeff Ondich) Wrote it. // ////////////////////////////////////////////////////////////////// #include #include int main( void ) { string s; int lineCount = 0; while( getline( cin, s ) ) { lineCount++; } cout << "Number of lines: " << lineCount << endl; return( 0 ); }