Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/basic string/insert"

From cppreference.com
< cpp‎ | string‎ | basic string
m (Text replace - "{{cpp|" to "{{c|")
m (r2.7.3) (Robot: Adding de, ja, pt, ru)
Line 87: Line 87:
 
{{dcl list template | cpp/string/basic_string/dcl list push_back}}
 
{{dcl list template | cpp/string/basic_string/dcl list push_back}}
 
{{dcl list end}}
 
{{dcl list end}}
 +
 +
[[de:cpp/string/basic string/insert]]
 +
[[ja:cpp/string/basic string/insert]]
 +
[[pt:cpp/string/basic string/insert]]
 +
[[ru:cpp/string/basic string/insert]]

Revision as of 16:56, 4 May 2012

Template:cpp/string/basic string/sidebar Template:ddcl list begin <tr class="t-dcl ">

<td >
iterator insert( iterator pos, CharT ch );
iterator insert( const_iterator pos, CharT ch );
</td>

<td > (1) </td> <td > (until C++11)
(since C++11) </td> </tr> <tr class="t-dcl ">

<td >
void insert( iterator pos, size_type count, CharT ch );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
basic_string& insert( size_type index, size_type count, CharT ch );
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
basic_string& insert( size_type index, const CharT* s );
</td>

<td > (4) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
basic_string& insert( size_type index, const CharT* s, size_type count );
</td>

<td > (5) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
basic_string& insert( size_type index, const basic_string& str );
</td>

<td > (6) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
basic_string& insert( size_type index, const basic_string& str,
                      size_type index_str, size_type count );
</td>

<td > (7) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class InputIterator >

void insert( iterator i, InputIterator first, InputIterator last );
template< class InputIterator >

iterator insert( const_iterator i, InputIterator first, InputIterator last );
</td>

<td > (8) </td> <td > (until C++11)

(since C++11) </td> </tr> <tr class="t-dcl ">

<td >
iterator insert( const_iterator pos, std::initializer_list<CharT> ilist );
</td>

<td > (9) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Inserts characters into the string:

1) inserts character ch before the character pointed by pos

2) inserts count copies of character ch before the element pointed to by pos

3) inserts count copies of character ch at the position index

4) inserts null-terminated character string pointed to by s at the position index. The length of the string is determined by the first null character.

5) inserts the first count characters from the character string pointed to by s at the position index. s can contain null characters.

6) inserts string str at the position index

7) inserts a string, obtained by str.substr(index_str, count) at the position index

8) inserts characters from the range [first, last)

9) inserts elements from initializer list ilist.

Contents

Parameters

pos - iterator before which the characters will be inserted
index - position at which the content will be inserted
ch - character to insert
s - pointer to the character string to insert
str - string to insert
first, last - range defining characters to be insert
count - number of characters to insert
index_str - position of the first character in the string str to insert.
ilist - initializer list to insert the characters from

Return value

1) iterator following the last inserted character.

2-7) *this

8-9) iterator following the last inserted character.

Complexity

See also

Template:cpp/string/basic string/dcl list appendTemplate:cpp/string/basic string/dcl list push back