string----------只适用于string操作

1.三个substr重载函数

2.六个append重载函数

3.十个replace重载函数

#include <iostream>
#include <string>

using namespace std;

int main( int argc, char **argv )
{
	string s("hello world");
	string s2 = s.substr(6,5);
	cout<<s2<<endl;
	string s3 = s.substr(6, 50);
	cout<<s3<<endl;

	s2 = s.substr(6);
	cout<<s2<<endl;

	s2 = s.substr();
	cout<<s2<<endl;

	s = "C++ Primer";

	s.append(" 3rd Ed.");
	cout<<s<<endl;

	s.insert(s.size(), "3rd Ed.");
	cout<<s<<endl;

	s.replace(11, 3, "4th");
	cout<<s<<endl;
	
	s.replace(11, 3, "Fourth");
	cout<<s<<endl;

	//replace
	s = "C++ Primer 3rd Ed.";
	s.erase(11, 3);
	s.insert(11, "Fourth");
	cout<<s<<endl;

	return 0;

}


posted @ 2015-03-02 15:59  SandKing  阅读(8)  评论(0)    收藏  举报  来源