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

原文地址:https://www.cnblogs.com/rong123/p/7727646.html