#include #include #include using namespace std; // The maximum number of rows we can read. const int MAX_ROWS = 20; // The maximum number of columns we can read + 1 for the // \0 c-string terminator. const int MAX_COLS = 100 + 1; int main() { cout << endl << "Write a file called a.txt" << endl << endl; ofstream out("a.txt"); out << "hello, this is line 1." << endl; out << "and now I welcome you to line 2." << endl; out << "but any good file will have three lines." << endl; out.close(); // read the file into buf char buf[20][100]; ifstream in("a.txt"); int lineNum = 0; while (in.getline(buf[lineNum],100)) { lineNum++; if (lineNum == MAX_ROWS) { break; } } cout << "Print row at a time\n-------------------\n"; for (int i=0; i < lineNum; i++) { cout << buf[i] << endl; } cout << endl; cout << "Print row at a time, character at a time\n" << "----------------------------------------\n"; for (int i=0; i < lineNum; i++) { int stringLength = strlen(buf[i]); for (int j=0;j