元の文字列でposとして添え字が付けられた文字の前に文字列strを挿入します
basic_string& insert (size_type pos, const basic_string& str);
strの添え字pos1から数えたn文字は、元の文字列の文字添え字posの前に挿入されます。
basic_string& insert (size_type pos, const basic_string& str, size_type pos1, size_type n);
元の文字列でposとして添え字が付けられた文字の前にn文字cを挿入します
basic_string& insert (size_type pos, size_type n, char c);
コード:
#include<iostream>
using namespace std;
int main()
{
string str="hello";
string s="Hahah";
str.insert(1,s);
cout<<str<<endl;
string str1="hello";
char c='w';
str1.insert(4,5,c);
cout<<str1<<endl;
string str2="hello";
string s2="weakhaha";
str2.insert(0,s2,1,3);
cout<<str2<<endl;
return 0;
}
動作結果:
元のリンク:
Insert()C ++文字列に関数を挿入