Download this source file
// LineNum.cpp - a program that prepends line numbers
// to each line read from the standard input, and
// outputs the result. Note that the use of setw manipulator
// requires the additional header file .
// This version demonstrates the use of the get member function.
//
// Written by Wayne Pollock, Tampa FL 1999
#include
#include
const int LINE_LENGTH = 256;
int main ()
{
int line_num = 1;
char ch, line[LINE_LENGTH];
while ( cin.get(line, LINE_LENGTH) )
{
while ( cin.get(ch) && ch != '\n' )
; // empty statement - skip to end of line
cout << setw(4) << line_num << ": " << line << endl;
++line_num;
}
return 0;
}