Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Invalid conversion" error in getline

Tags:

c++

getline

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.

like image 670
Sanuuu Avatar asked Jun 27 '26 18:06

Sanuuu


1 Answers

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);

    <...>
}
like image 68
geekpp Avatar answered Jun 30 '26 07:06

geekpp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!