开发者

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

Which one is bet开发者_开发问答ter 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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜