差异:cin.getline()和getline(cin,st)

use*_*855 6 c++ stl

哪一个更好,更受欢迎?我真的觉得阅读API令人困惑.

Ker*_* SB 9

成员版本读入a char*,免费版本读入a std::string.所以更喜欢免费版!像这样使用它:

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