string (1) | string& insert (size_t pos, const string& str); |
---|---|
substring (2) | string& insert (size_t pos, const string& str, size_t subpos, size_t sublen); |
c-string (3) | string& insert (size_t pos, const char* s); |
buffer (4) | string& insert (size_t pos, const char* s, size_t n); |
fill (5) | string& insert (size_t pos, size_t n, char c); iterator insert (const_iterator p, size_t n, char c); |
single character (6) | iterator insert (const_iterator p, char c); |
range (7) | template <class InputIterator> iterator insert (iterator p, InputIterator first, InputIterator last); |
initializer list (8) | string& insert (const_iterator p, initializer_list<char> il); |
#include <iostream>
#include <string>
using namespace std;
main int ()
{
String S1 = "I Lyy";
String S2 = "Love";
s1.insert (2, S2); // s1 2 is inserted into the position S2
COUT S1 << << endl;
String S3 = "aaenjoy00 ";
s1.insert (2, s3, 2,. 5); // s1 position s3 of the insertion position of 2 2 5 characters beginning
COUT S1 << << endl;
s1.insert (. 7," "); / / 7 insertion position s1 space, a unit of the original backward
COUT << s1 << endl;
const char * S4 = "like";
s1.insert (2, "");
s1.insert (2, S4) ;
COUT << s1 << endl;
const char * s5 = "Fond $$";
s1.insert (2, "");
s1.insert (2, s5,. 4); // inserted at the position s1, s5 The first four characters
COUT S1 << << endl;
s1.insert (2, "");
S1.insert (2, 5, '@ '); // @ 5 is inserted in position 2
COUT S1 << << endl;
s1.insert (2, "");
s1.insert (s1.begin () + 2, 4, '$'); // $ inserted in position 4 of the iterator
COUT S1 << << endl;
s1.insert (2, "");
S1. insert (s1.begin () + 2, '?'); // inserted in a position iterator?
COUT S1 << << endl;
String S6 = "!! @@ BE Keen oN";
s1.insert ( 2, "");
s1.insert (s1.begin () + 2, s6.begin () + 2, s6.end () -2); // iterator s6 inserted position s1 in the iteration range
cout S1 << endl <<;
return 0;
}