string------修改

  s.insert( itr, t )                                           s.insert(pos, n, c)

  s.insert( itr, n, t )                                       s.insert(pos,  s2)                        

  s.insert( itr, b, e )                                      s.insert(pos, s2,  pos2, len)

  s.assign(b, e)                                          s.insert(pos,  cp, len)

  s.assign(n, t)                                            s.insert(pos,  cp)

  s.erase(itr)                                                 s.assign(s2)

  s.erase(itr, e)                                             s.assign(s2, pos2, len)

                                                                      s.assign(cp, len)

                                                                      s.assign(cp)

                                                                      s.erase( pos, len )


#include <iostream>
#include <string>

using namespace std;

int main( int argc, char** argv )
{
	string s("hello");
	string s2("abcdef");

	string::iterator itr = s.begin();

	s.insert(itr, 'A');
	cout<<s<<endl;
	
	itr = s.begin();
	s.insert(itr, 3, 'B');
	cout<<s<<endl;


	string::iterator b = s2.begin();
	string::iterator e = s2.end();
	itr = s.begin();
	s.insert(itr, b, e);
	cout<<s<<endl;

	s = "hello";
	cout<<s<<endl;

	s.assign(b,e);
	cout<<s<<endl;

	s.assign(8, 'K');
	cout<<s<<endl;

	s = "abcdef";
	itr = s.begin();
	s.erase(itr);
	cout<<s<<endl;
	
	b = s.begin();
	b++;
	b++;
	e = s.end();
	e--;
	s.erase( b, e );
	cout<<s<<endl;

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main( int argc, char** argv )
{
	string s("hello");
	string s2("abcdef");

	string::iterator itr = s.begin();

	s.insert(itr, 'A');
	cout<<s<<endl;
	
	itr = s.begin();
	s.insert(itr, 3, 'B');
	cout<<s<<endl;


	string::iterator b = s2.begin();
	string::iterator e = s2.end();

	s = "hello";
	s2 = "abc";
	s.insert(0, 3, 'A');
	cout<<s<<endl;

	s.insert(5,s2);
	cout<<s<<endl;

	s2 = "123456";
	s.insert(0, s2, 2, 3);
	cout<<s<<endl;

	char *cp = "Stately plump Buck";
	s.assign(cp, 7);
	cout<<s<<endl;

	s.assign(cp);
	cout<<s<<endl;

	s = "hello";
	s.insert(0, cp, 7);
	cout<<s<<endl;

	s.insert(0, cp);
	cout<<s<<endl;

	s = "hello";
	s2 = "abcdef";

	s.assign(s2, 2, 3);
	cout<<s<<endl;

	s.assign(s2);
	cout<<s<<endl;

	s.erase(2, 3);
	cout<<s<<endl;

	s = "123456789";
	s.erase(s.size()-5, 5);
	cout<<s<<endl;

	s.insert(s.size(), 5, '!');
	cout<<s<<endl;

	s = "abc";
	s.erase(0, 1).insert(0, "A");
	cout<<s<<endl;

	s = "abc";
	s[0] = 'A';
	cout<<s<<endl;

	return 0;
}



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