简体   繁体   中英

Difference: cin.getline() and getline(cin, st)

Which one is better and preferred? I am really finding the reading API confusing.

The member version reads into a char* , the free version reads into a std::string . So prefer the free version! Use it like this:

std::istream & ins = /* ... */;
std::string line;
while (std::getline(ins, line))
{
  // process line
}

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