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

来源:互联网 发布:银行证券软件下载 编辑:程序博客网 时间:2024/05/29 15:09

头文件:

#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;}

这里写图片描述

0 0
原创粉丝点击