1. string& operator+= ( const string& str );
  2. string& operator+= ( const char* s );
  3. string& operator+= ( char c );
  4. //Appends a copy of the argument to the string.
  1. string& append ( const string& str );
  2. string& append ( const string& str, size_t pos, size_t n );
  3. string& append ( const char* s, size_t n );
  4. string& append ( const char* s );
  5. string& append ( size_t n, char c );
  6. template <class InputIterator>
  7.    string& append ( InputIterator first, InputIterator last );
  8. //The current string content is extended by adding an additional appending string at its end.
  1. void push_back ( char c );
  2. //Appends a single character to the string content, increasing its size by one.
  1. string& assign ( const string& str );
  2. string& assign ( const string& str, size_t pos, size_t n );
  3. string& assign ( const char* s, size_t n );
  4. string& assign ( const char* s );
  5. string& assign ( size_t n, char c );
  6. template <class InputIterator>
  7.    string& assign ( InputIterator first, InputIterator last );
  8. //Assigns new content to the string replacing its current content.
  1. string& insert ( size_t pos1, const string& str );
  2.  string& insert ( size_t pos1, const string& str, size_t pos2, size_t n );
  3.  string& insert ( size_t pos1, const char* s, size_t n);
  4.  string& insert ( size_t pos1, const char* s );
  5.  string& insert ( size_t pos1, size_t n, char c );
  6. iterator insert ( iterator p, char c );
  7.     void insert ( iterator p, size_t n, char c );
  8. template<class InputIterator>
  9.     void insert ( iterator p, InputIterator first, InputIterator last );
  10. //The current string content is extended by inserting some additional content at a specific location within the string content (this position is determined by either pos1 or p, depending on the function version used).
  1. string& erase ( size_t pos = 0, size_t n = npos );
  2. iterator erase ( iterator position );
  3. iterator erase ( iterator first, iterator last );
  4. //Erases a part of the string content, shortening the length of the string.
  1. string& replace ( size_t pos1, size_t n1, const string& str );
  2. string& replace ( iterator i1, iterator i2, const string& str );

  3. string& replace ( size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2 );

  4. string& replace ( size_t pos1, size_t n1, const char* s, size_t n2 );
  5. string& replace ( iterator i1, iterator i2, const char* s, size_t n2 );

  6. string& replace ( size_t pos1, size_t n1, const char* s );
  7. string& replace ( iterator i1, iterator i2, const char* s );

  8. string& replace ( size_t pos1, size_t n1, size_t n2, char c );
  9. string& replace ( iterator i1, iterator i2, size_t n2, char c );

  10. template<class InputIterator>
  11.    string& replace ( iterator i1, iterator i2, InputIterator j1, InputIterator j2 );
  12. //Replaces a section of the current string by some other content determined by the arguments passed.
  1. void swap ( string& str );
  2. //Swaps the contents of the string with those of string object str, such that after the call to this member function, the contents of this string are those which were in str before the call, and the contents of str are those which were in this string.
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;

  4. int
  5. main(void)
  6. {
  7.         string name ("Sam");
  8.         string family ("Andy");
  9.         name += "Y.";
  10.         name += family;
  11.         name += '\n';
  12.         cout << name << endl;

  13.         string str;
  14.         string str2 = "Writing ";
  15.         string str3 = "print 10 and then 5 more";

  16.         str.append(str2);
  17.         str.append(str3, 6, 3);
  18.         str.append("dots are cool", 5);
  19.         str.append("here: ");
  20.         str.append(10, '.');
  21.         str.append(str3.begin()+8, str3.end());
  22.         str.append<int>(5,0x2E);
  23.         cout << str << endl;

  24.         string s ("Hello");
  25.         s.push_back('C');
  26.         cout << s << endl;

  27.         string t;
  28.         string t1 = "World";
  29.         t.assign(t1);
  30.         cout << t << endl;
  31.         t.assign(t1, 2, 2);
  32.         cout << t << endl;
  33.         t.assign("how are you", 8);
  34.         cout << t << endl;
  35.         t.assign("fine");
  36.         cout << t << endl;
  37.         t.assign(10,'*');
  38.         cout << t << endl;
  39.         t.assign<int>(10,0x2D);
  40.         cout << t << endl;
  41.         t.assign(t1.begin()+2, t1.end()-1);
  42.         cout << t << endl;


  43.         string r="to be question";
  44.         string r2="the ";
  45.         string r3="or not to be";
  46.         string::iterator it;

  47.         // used in the same order as described above:
  48.         r.insert(6,r2); // to be (the )question
  49.         r.insert(6,r3,3,4); // to be (not )the question
  50.         r.insert(10,"that is cool",8); // to be not (that is )the question
  51.         r.insert(10,"to be "); // to be not (to be )that is the question
  52.         r.insert(15,1,':'); // to be not to be(:) that is the question
  53.         it = r.insert(r.begin()+5,','); // to be(,) not to be: that is the question
  54.         r.insert (r.end(),3,'.'); // to be, not to be: that is the question(...)
  55.         r.insert (it+2,r3.begin(),r3.begin()+3); // (or )
  56.         cout << r << endl;

  57.         string he (" world ");
  58.         string she (" hello ");
  59.         he.swap(she);
  60.         cout << he << she << endl;

  61.         return (0);
  62. }

10-23 07:15