Espacios de nombres
Variantes
Acciones

std::basic_string::replace

De cppreference.com
< cpp‎ | string‎ | basic string
 
 
Strings biblioteca
Terminadas en nulo
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cadenas de bytes
Multibyte cuerdas
Cadenas anchas
Clases
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
std::basic_string
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Elemento acceso
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los iteradores
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Capacidad
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Operaciones
Original:
Operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::replace
Buscar
Original:
Search
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Constantes
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Terceros funciones
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Clases de ayuda
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
basic_string& replace( size_type pos, size_type count,

                       const basic_string& str );

basic_string& replace( const_iterator first, const_iterator last,

                       const basic_string& str );
(1)
basic_string& replace( size_type pos, size_type count,

                       const basic_string& str,
                       size_type pos2, size_type count2 );

template< class InputIt >
basic_string& replace( const_iterator first, const_iterator last,

                       InputIt first2, InputIt last2 );
(2)
basic_string& replace( size_type pos, size_type count,

                       const CharT* cstr, size_type count2 );

basic_string& replace( const_iterator first, const_iterator last,

                       const CharT* cstr, size_type count2 );
(3)
basic_string& replace( size_type pos, size_type count,

                       const CharT* cstr );

basic_string& replace( const_iterator first, const_iterator last,

                       const CharT* cstr );
(4)
basic_string& replace( size_type pos, size_type count,

                       size_type count2, CharT ch );

basic_string& replace( const_iterator first, const_iterator last,

                       size_type count2, CharT ch );
(5)
basic_string& replace( const_iterator first, const_iterator last,
                       std::initializer_list<CharT> ilist );
(6) (desde C++11)
Sustituye a la parte de la cadena indicada con [pos, pos + count) o [first, last) con una nueva cadena .
Original:
Replaces the part of the string indicated by either [pos, pos + count) or [first, last) with a new string.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
La nueva cadena puede ser uno de:
Original:
The new string can be one of:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
cadena str
Original:
string str
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
subcadena [pos2, pos2 + count2) de str o personajes de la [first2, last2) rango
Original:
substring [pos2, pos2 + count2) of str or characters in the range [first2, last2)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
charcters primera count2 de la cadena de caracteres apuntada por cstr
Original:
first count2 charcters of the character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
terminada en nulo cadena de caracteres apuntada por cstr
Original:
null-terminated character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
count2 copias de ch carácter
Original:
count2 copies of character ch
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
personajes de la ilist lista de inicialización
Original:
characters in the initializer list ilist
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Parámetros

pos -
inicio de la subcadena que va a ser sustituido
Original:
start of the substring that is going to be replaced
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count -
La longitud de la subcadena que va a ser sustituido
Original:
length of the substring that is going to be replaced
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
first, last -
rango de caracteres que va a ser sustituido
Original:
range of characters that is going to be replaced
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
str -
cadena que se utiliza para el reemplazo
Original:
string to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pos2 -
el inicio de la subcadena para reemplazarlo
Original:
start of the substring to replace with
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count2 -
número de caracteres a reemplazar
Original:
number of characters to replace with
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cstr -
puntero a la cadena de caracteres a usar para la sustitución
Original:
pointer to the character string to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ch -
carácter valor a utilizar para la sustitución
Original:
character value to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
first2, last2 -
rango de caracteres a utilizar para la sustitución
Original:
range of characters to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
init -
inicializador lista con los caracteres que se utilizará para el reemplazo
Original:
initializer list with the characters to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Requerimientos de tipo
-
InputIt debe reunir los requerimientos de InputIterator.

[editar] Valor de retorno

*this

[editar] Excepciones

std::out_of_range if pos > length() or pos2 > str.length()

std::length_error si la cadena resultante exceda la longitud máxima posible del string (std::string::npos - 1)
Original:
std::length_error if the resulting string will exceed maximum possible string length (std::string::npos - 1)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Ejemplo

#include <iostream>
#include <string>
 
int main()
{
    std::string str("The quick brown fox jumps over the lazy dog.");
 
    str.replace(10, 5, "red"); // (4)
 
    str.replace(str.begin(), str.begin() + 3, 1, 'A'); // (5)
 
    std::cout << str << '\n';
}

Salida:

A quick red fox jumps over the lazy dog.