Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | string‎ | basic string
m (Text replace - "putIterator" to "putIt")
(+type reqs)
Line 67: Line 67:
 
{{param list item | index_str | position of the first character in the string {{tt|str}} to insert.}}
 
{{param list item | index_str | position of the first character in the string {{tt|str}} to insert.}}
 
{{param list item | ilist | initializer list to insert the characters from}}
 
{{param list item | ilist | initializer list to insert the characters from}}
 +
{{param list hreq}}
 +
{{param list req concept | InputIt | InputIterator}}
 
{{param list end}}  
 
{{param list end}}  
  

Revision as of 06:13, 3 August 2012

 
 
 
std::basic_string
Member functions
Element access
Iterators
Capacity
Modifiers
basic_string::insert
Search
Operations
Constants
Non-member functions
I/O
Comparison
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
Numeric conversions
(C++11)(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Literals
Helper classes
Deduction guides (C++17)

 

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 InputIt >

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

iterator insert( const_iterator i, InputIt first, InputIt 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
Type requirements
-
InputIt must meet the requirements of LegacyInputIterator.

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