开发者

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

开发者 https://www.devze.com 2023-03-31 15:05 出处:网络
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 ve

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

精彩评论

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