string
#include "stdafx.h"
#include<string>
#include<list>
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string str("abc");
str[0] ;
cout << str[0] << endl;
cout << str.c_str()<<endl;//输出abc
string str2("123");
str = str + str2;
cout << str << endl;
str = str + "esf" + "++";
cout << str << endl;
cout << "*******************************" << endl;
int pos=str.find("_");//找到加号,并返回该加号的索引值,//如果没找到就返回-1,找到返回索引值
cout << pos << endl;
pos = str.find_first_not_of('+');//找第一个不是加号的,并返回索引值
cout << pos << endl;
pos = str.find_first_of('+');//找第一个是加号的,并返回索引值
pos = str.find_last_not_of('+'); //找最后一个不是加号的,并返回索引值
pos = str.find_first_of('+');//找最后一个是加号的,并返回索引值
cout << "*****************************" << endl;
//string strsub = str.substr(0,3);//获得【0,3)的子串
string strsub = str.substr(3);//获得3到后面的子串
cout << strsub << endl;
cout << "*****************************" << endl;
list<string> strlist;//一个string类型的list容器
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步