区别:cin.getline()和getline(cin,st) [英] Difference: cin.getline() and getline(cin, st)
本文介绍了区别:cin.getline()和getline(cin,st)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪一个更好,更好?我真的发现阅读API混乱。
Which one is better and preferred? I am really finding the reading API confusing.
推荐答案
成员版本读入一个 char *
读入 std :: string
。所以更喜欢免费版!使用它像这样:
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
}
这篇关于区别:cin.getline()和getline(cin,st)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文