gpt4 book ai didi

c++ - std::getline() 是否完全清空缓冲区?

转载 作者:搜寻专家 更新时间:2023-10-31 00:56:09 24 4
gpt4 key购买 nike

是 std::getline() 完全清空了缓冲区,还是输入缓冲区中还剩下换行符?

最佳答案

作为the page状态:

If the delimiter is found, it is extracted and discarded (i.e. it is not stored and the next input operation will begin after it).

它应该被丢弃。

查看 this example.两个句子之间的换行符被适本地丢弃。


回复评论:

(1) istream& getline (istream& is, string& str, char delim);

(2) istream& getline (istream& is, string& str);

Extracts characters from is and stores them into str until the delimitation character delim is found (or the newline character, '\n', for (2)).

是的,换行符作为默认分隔符。

不,输入缓冲区将不再有换行符,因为它会被简洁地丢弃。您不需要自己清洁。

关于c++ - std::getline() 是否完全清空缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40200274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com