简体   繁体   中英

C++ - No matching function for call to 'getline'

I cannot figure out the proper syntax for a file istream getline() call

I've tried so many variations of calling getline() with all different kinds of parameters and after looking at several different pieces of documentation and it just won't work.

std::ifstream in("file.txt");
char tmp;
std::getline(tmp, in);

This one results in

../directory/file.cpp:178:2: error: no matching function for call to 'getline'
    std::getline(tmp, in);
    ^~~~~~~~~~~~

But other documentation says

std::ifstream in("file.txt");
char tmp;
in.getline(tmp);

which also spits out

../directory/file.cpp:179:5: error: no matching member function for call to
  'getline'
    in.getline(tmp);
    ^~~~~~~~~~~~

All I need to do is read a file line by line and I can't figure it out. Could someone please point me in the right direction? I can provide more information if needed.

getline() reads string, but you pass it a single char.

Use it like this:

std::ifstream in("file.txt");
std::string tmp;
std::getline(in, tmp);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM