gpt4 book ai didi

c++ - 你能在 std::getline 中指定什么不是定界符吗?

转载 作者:太空狗 更新时间:2023-10-29 20:29:41 25 4
gpt4 key购买 nike

我想让它把任何不是字母字符的东西都当作分隔符。我该怎么做?

最佳答案

你不能。默认分隔符是 \n :

while (std::getline (std::cin, str) // '\n' is implicit

对于其他分隔符,传递它们:

while (std::getline (std::cin, str, ' ') // splits at a single whitespace

但是,分隔符是char类型的,所以只能使用一个“分割字符”,不能匹配什么不匹配。

如果您的输入恰好位于容器内,如 std::string , 你可以使用 find_first_not_offind_last_not_of .


在你的另一个问题中,你确定你已经考虑了所有的答案吗?一个使用istream::operator>>(std::istream&, <string>) , 它将匹配一系列非空白字符。

关于c++ - 你能在 std::getline 中指定什么不是定界符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9272276/

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