gpt4 book ai didi

c++ - 如何检查字符串是否包含字符?

转载 作者:IT老高 更新时间:2023-10-28 22:24:27 32 4
gpt4 key购买 nike

我有一个想要阅读的文本文件。我想知道其中一行是否包含 [ 所以我尝试了:

if(array[i] == "[")

但这不起作用。

如何检查字符串是否包含某个字符?

最佳答案

查看文档 string::find

std::string s = "hell[o";
if (s.find('[') != std::string::npos)
; // found
else
; // not found

关于c++ - 如何检查字符串是否包含字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43629363/

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