#include #include #include #include "CPstring.h" // file: format.cc; author: D. Ramm; date: 10/15/96 // file input; while with EOF to exit // simple word processing int main() { string margin, word; int k; string filename, maring = ""; ifstream win; const int LFTMARGIN = 10; const int COLWIDTH = 40; int leng, position = 0; cout << "Enter file name: "; cin >> filename; win.open(filename); for (k = 0; k < LFTMARGIN; k++) margin += " "; cout << endl << endl << margin; while (win >> word) { leng = word.length(); position += leng + 1; if (position > COLWIDTH) { position = leng + 1; cout << endl << margin; } cout << word << " "; } cout << endl << endl; return 0; } Sample output: format Enter file name: wordfile It was the night before Christmas, When all through the house, Not a creature was stirring, Not even a mouse. cat wordfile It was the night before Christmas, When all through the house, Not a creature was stirring, Not even a mouse.