您的位置:首页 > 其它

string类的常用的几个小东西find,substr

2016-05-13 14:43 232 查看
头文件:

#include<iostream>
#include<string>


定义:

string ss;


#include<iostream>
#include<string>
int main()
{
string ss;
while(1)
{
getline(cin,ss);
cout<<ss<<endl;

int a;
a=ss.find('a');
printf("a=%d\n",a);

string temp;

temp=ss;
cout<<temp<<endl;

temp=ss.substr(2,3); //在ss中的第2个(包括第二个)开始的3个字符
cout<<temp<<endl;

temp=ss+ss.substr(2,3); //ss+在ss中的第2个(包括第二个)开始的3个字符
cout<<temp<<endl;

temp=ss+ss.substr(2); //ss+在ss中的第2个(包括第二个)开始的以后全部
cout<<temp<<endl;

}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: