Hey guys, thanks in advance for the help.
I'm fairly new to C++, so the code should look very simple to the guru crowd. When I try to compile the short program below, I get the error that "struct std:: ofstream has no member function 'getline'". I've checked around a bit and this line is used fine elsewhere, as well as in the book I'm learning from. Here's the code, with the problem area bolded:
Code:#include<iostream> #include<fstream> using namespace std; int main() { int c,i; char filename[81], input_line[101]; cout << "Enter a filename and press enter: "; //prompt for filename cin.getline(filename, 80); ofstream file_in(filename); if (!file_in) { //avoiding errors cout << "File " << filename << "could not be opened."; return -1; } while (1) { //prints five lines of the selected file at a time for (i = 1; i < 5 && !file_in.eof(); i++) { file_in.getline(input_line, 100); cout << input_line << "\n"; } if (file_in.eof()) { //exits if end of file is reached break; } cout << "More? (Press 'Q' and ENTER to quit): "; //ask user if they want more printed cin.getline(input_line, 80); c = input_line[0]; if (c == 'Q' || c == 'q') { break; } } cin.get(); return 0; }



LinkBack URL
About LinkBacks



