- string& operator+= ( const string& str );
- string& operator+= ( const char* s );
- string& operator+= ( char c );
- //Appends a copy of the argument to the string.
- string& append ( const string& str );
- string& append ( const string& str, size_t pos, size_t n );
- string& append ( const char* s, size_t n );
- string& append ( const char* s );
- string& append ( size_t n, char c );
- template <class InputIterator>
- string& append ( InputIterator first, InputIterator last );
- //The current string content is extended by adding an additional appending string at its end.
- void push_back ( char c );
- //Appends a single character to the string content, increasing its size by one.
- string& assign ( const string& str );
- string& assign ( const string& str, size_t pos, size_t n );
- string& assign ( const char* s, size_t n );
- string& assign ( const char* s );
- string& assign ( size_t n, char c );
- template <class InputIterator>
- string& assign ( InputIterator first, InputIterator last );
- //Assigns new content to the string replacing its current content.
- string& insert ( size_t pos1, const string& str );
- string& insert ( size_t pos1, const string& str, size_t pos2, size_t n );
- string& insert ( size_t pos1, const char* s, size_t n);
- string& insert ( size_t pos1, const char* s );
- string& insert ( size_t pos1, size_t n, char c );
- iterator insert ( iterator p, char c );
- void insert ( iterator p, size_t n, char c );
- template<class InputIterator>
- void insert ( iterator p, InputIterator first, InputIterator last );
- //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).
- string& erase ( size_t pos = 0, size_t n = npos );
- iterator erase ( iterator position );
- iterator erase ( iterator first, iterator last );
- //Erases a part of the string content, shortening the length of the string.
- string& replace ( size_t pos1, size_t n1, const string& str );
- string& replace ( iterator i1, iterator i2, const string& str );
- string& replace ( size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2 );
- string& replace ( size_t pos1, size_t n1, const char* s, size_t n2 );
- string& replace ( iterator i1, iterator i2, const char* s, size_t n2 );
- string& replace ( size_t pos1, size_t n1, const char* s );
- string& replace ( iterator i1, iterator i2, const char* s );
- string& replace ( size_t pos1, size_t n1, size_t n2, char c );
- string& replace ( iterator i1, iterator i2, size_t n2, char c );
- template<class InputIterator>
- string& replace ( iterator i1, iterator i2, InputIterator j1, InputIterator j2 );
- //Replaces a section of the current string by some other content determined by the arguments passed.
- void swap ( string& str );
- //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.
- #include <iostream>
- #include <string>
- using namespace std;
- int
- main(void)
- {
- string name ("Sam");
- string family ("Andy");
- name += "Y.";
- name += family;
- name += '\n';
- cout << name << endl;
- string str;
- string str2 = "Writing ";
- string str3 = "print 10 and then 5 more";
- str.append(str2);
- str.append(str3, 6, 3);
- str.append("dots are cool", 5);
- str.append("here: ");
- str.append(10, '.');
- str.append(str3.begin()+8, str3.end());
- str.append<int>(5,0x2E);
- cout << str << endl;
- string s ("Hello");
- s.push_back('C');
- cout << s << endl;
- string t;
- string t1 = "World";
- t.assign(t1);
- cout << t << endl;
- t.assign(t1, 2, 2);
- cout << t << endl;
- t.assign("how are you", 8);
- cout << t << endl;
- t.assign("fine");
- cout << t << endl;
- t.assign(10,'*');
- cout << t << endl;
- t.assign<int>(10,0x2D);
- cout << t << endl;
- t.assign(t1.begin()+2, t1.end()-1);
- cout << t << endl;
- string r="to be question";
- string r2="the ";
- string r3="or not to be";
- string::iterator it;
- // used in the same order as described above:
- r.insert(6,r2); // to be (the )question
- r.insert(6,r3,3,4); // to be (not )the question
- r.insert(10,"that is cool",8); // to be not (that is )the question
- r.insert(10,"to be "); // to be not (to be )that is the question
- r.insert(15,1,':'); // to be not to be(:) that is the question
- it = r.insert(r.begin()+5,','); // to be(,) not to be: that is the question
- r.insert (r.end(),3,'.'); // to be, not to be: that is the question(...)
- r.insert (it+2,r3.begin(),r3.begin()+3); // (or )
- cout << r << endl;
- string he (" world ");
- string she (" hello ");
- he.swap(she);
- cout << he << she << endl;
- return (0);
- }
10-23 07:15