Having code troubles with cin.getline
Posted: Sun Jul 26, 2009 4:13 pm
Im writing a console program, and I am having some serious problems.
First off, here is the code
The error occurs on line 15( the one with the comment "THIS IS THE ERROR LINE" ). I'm using Code::Blocks on windows, and here is the error message.
Usually I don't have problems debugging my code, but that error message really confuses me.
First off, here is the code
Code: Select all
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string filename;
string input_line; // Input line for text entry
cout << "Enter a file name and press ENTER: ";
cin.getline(cin, filename); //THIS IS THE ERROR LINE
ofstream file_out(filename);
if (! file_out) {
cout << "File " << filename << " could not be opened.";
return -1;
}
cout << "File " << filename << " was opened." << endl;
while (1) {
cout << "Enter line (@@@ to quit)>>";
cin.getline(cin, input_line);
if (strcmp(input_line, "@@@") == 0)
break;
file_out << input_line << endl;
}
file_out.close();
return 0;
}
Code: Select all
error: no matching function for call to `std::basic_istream<char, std::char_traits<char> >::getline(std::istream&, std::string&)'|