求C++中处理字符(串)的函数

[复制链接]
查看11 | 回复3 | 2011-10-18 23:01:49 | 显示全部楼层 |阅读模式
#include#includeusing namespace std;int find(string &,char);void main(){string str="adfsdf@afd";char cd='@';int index=find(str,cd);if(index!=-1)cout<<"字符@存在并且索引为:"<<index<<endl;}int find(string & ss,char ch){int i=0;while(i<ss.size()){if(ss==ch)return i;i++;}return -1;...
回复

使用道具 举报

千问 | 2011-10-18 23:01:49 | 显示全部楼层
str.find('@', 0) == std::string::npos对你这问题,find_first_of 也可以。几种用法性能有差别,要看你的要求。...
回复

使用道具 举报

千问 | 2011-10-18 23:01:49 | 显示全部楼层
用正则表达式。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行