string::append

string (1)
string& append (const string& str);
substring (2)
string& append (const string& str, size_t subpos, size_t sublen);
c-string (3)
string& append (const char* s);
buffer (4)
string& append (const char* s, size_t n);
fill (5)
string& append (size_t n, char c);
range (6)
template <class InputIterator>
   string& append (InputIterator first, InputIterator last);
initializer list(7)
string& append (initializer_list<char> il);

using namespace std;
int main()
{
string s1 = "abc";
string s2 = "def";
s1.append(s2);
cout << "1 " << s1 << endl;
string s3 = "ghi";
try{
s1.append(s3, 4, 3);
}catch(out_of_range){
cout << "out_of_range" << endl;
}
cout << "2 " << s1 << endl;
const char *s4 = "hello";
s1.append(s4);
cout << s1 << endl;
const char *s5 = "weather";
s1.append(s5, 3);
cout << s1 << endl;
s1.append(5, '$');
cout << s1 << endl;
string s6 = "12345";
s1.append(s6.begin() + 1, s6.end() - 2);
cout << s1 << endl;
initializer_list<char> s7 = {'q', 'w', 'e', 'r'};
s1.append(s7);
cout << s1 << endl;
return 0;
}

猜你喜欢

转载自www.cnblogs.com/xpylovely/p/12082244.html