#include #include using namespace std; int const MAX = 51; void read(ifstream &, char []); int main() { // create file object and open the datafile ifstream infile("read.txt"); if (!infile) { cerr << "File could not be opened." << endl; return 1; } for (;;) { char s[MAX]; read(infile, s); if (infile.eof()) break; cout << s << endl; } return 0; } void read(ifstream& infile, char s[]) { int i = 1; s[0] = infile.get(); if (infile.eof() || s[0] == '\n') { s[0] = '\0'; return; } while (i < MAX) { s[i] = infile.get(); if (s[i] == '\n') break; else i++; } s[i] = '\0'; }