error no instance of overloaded function "getline" matches the argument list
I cant seem to see what is wrong. I feel like I am passing the correct arguments (ie the std::ofstream
and the std::string
). Any help would be great thanks.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
ofstream yourFile;
myfile.open ("read.cc");
yourFile.open ("write.cpp");
string line;
This section in particular is the one that is getting an error.
if (myfile.is_open()){
The getline in the while loop is red and is giving me the overload error.
while(getline(myfile,line)){
yourFile << line <<"\n";
}
}
myfile.close();
yourFile.close();
return 0;
}
I thought I had set up the streams correctly.
An output stream is for writing to. For reading from, you want an input stream:
std::ifstream myFile;
// ^^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.