c++怎么判断字符串中是否包含某个字符
lewis
2017-11-02
21次阅读
在C++中,你可以使用`std::string`类的成员函数`find()`来判断一个字符串中是否包含某个字符。`find()`函数返回该字符在字符串中第一次出现的位置,如果未找到,则返回一个特殊的值 `std::string::npos`。
以下是一个示例代码:
#include
#include
intmain(){
std::stringstr="Hello,World!";
charch='o';
size_tfound=str.find(ch);
if(found!=std::string::npos){
std::cout 
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。