in this one program I'm trying to read a third line of text from a file and then take only its ending after the last space. When I'm using the getline function however it gives me a
idp_handler.cc:37: error: invalid conversion from ‘void*’ to ‘char’ (line 37 is the line of the first getline)
Here goes my code
void idp_handler::resume() {
ofstream myfile;
myfile.open (PATH_R);
string read;
getline (myfile, read);
getline (myfile, read);
getline (myfile, read);
for(int i = read.size()-1; read[i]==' '; i--) read = read.substr(i,read.size()-i);
cout << "karp" << read << "karp" << endl;
}
PATH_R is just a path leading to the file I'm reading from.
You should be using std::ifstream, and always prefix with std:: instead of importing std namespace to the global one to avoid collisions :
void idp_handler::resume() {
std::ifstream myfile;
myfile.open (PATH_R);
std::string read;
std::getline (myfile, read);
std::getline (myfile, read);
std::getline (myfile, read);
<...>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With