Share via


<string>

Define la clase de plantilla basic_string de contenedor y las plantillas diferentes que admiten.

Para obtener más información sobre basic_string, vea basic_string Class.

namespace std {
    template<class CharType>
        class char_traits;
    template<>
        class char_traits<char>;
    template<>
        class char_traits<wchar_t>;
    template<>
        class char_traits<char16_t>; 
    template<>
        class char_traits<char32_t>;

    template<
        class CharType,
        class Traits = char_traits<CharType>,
        class Allocator = allocator<CharType> 
    > class basic_string;

    typedef basic_string<char> string;
    typedef basic_string<wchar_t> wstring;
    typedef basic_string<char16_t> u16string;
    typedef basic_string<char32_t> u32string;

        // NARROW FUNCTIONS
    int stoi (
        const string& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    long stol (
        const string& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    unsigned long stoul (
        const string& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    long long stoll (
        const string& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    unsigned long long stoull (
        const string& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    float stof (
        const string& _Str, 
        size_t *_Idx = 0
    );
    double stod (
        const string& _Str, 
        size_t *_Idx = 0
    );
    long double stold (
        const string& _Str, 
        size_t *_Idx = 0
    );

    string to_string (long long _Val); 
    string to_string (unsigned long long _Val); 
    string to_string (long double _Val);

        // WIDE FUNCTIONS
    int stoi (
        const wstring& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    long stol (
        const wstring& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    unsigned long stoul (
        const wstring& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    long long stoll (
        const wstring& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    );
    unsigned long long stoull (
        const wstring& _Str, 
        size_t *_Idx = 0,
        int _Base = 10
    ); 
    float stof (
        const wstring& _Str, 
        size_t *_Idx = 0
    ); 
    double stod (
        const wstring& _Str, 
        size_t *_Idx = 0
    );
    long double stold (
        const wstring& _Str, 
        size_t *_Idx = 0
    );
    wstring to_wstring (long long _Val); 
    wstring to_wstring (unsigned long long _Val); 
    wstring to_wstring (long double _Val);

       // TEMPLATE FUNCTIONS
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator> operator+ (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator> operator+ (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator> operator+ (
            const basic_string<CharType, Traits, Allocator>& _Left,
            CharType _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator> operator+ (
            const CharType *_Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator> operator+ (
            CharType _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );

    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator>&& operator+ (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>&& _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator>&& operator+ (
            const basic_string<CharType, Traits, Allocator>&& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator>&& operator+ (
            const basic_string<CharType, Traits, Allocator>&& _Left,
            const basic_string<CharType, Traits, Allocator>&& _Right
        );
    template<class CharType, class Traits, class Allocator> 
        basic_string<CharType, Traits, Allocator>&& operator+ (
            const basic_string<CharType, Traits, Allocator>&& _Left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator>&& operator+ (
            const basic_string<CharType, Traits, Allocator>&& _Left,
            CharType _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator>&& operator+ (
            const CharType *_Left,
            const basic_string<CharType, Traits, Allocator>&& _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_string<CharType, Traits, Allocator>&& operator+ (
            CharType _Left,
            const basic_string<CharType, Traits, Allocator>&& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator== (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator== (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator== (
            const CharType *_Left, 
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator!= (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator!= (
            const basic_string<CharType, Traits, Allocator>& left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator!= (
            const CharType *_Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator< (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator< (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator< (
            const CharType *_Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator>= (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator>= (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator>= (
            const CharType *_Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator> (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator> (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator> (
            const CharType *_Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator<= (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator<= (
            const basic_string<CharType, Traits, Allocator>& _Left,
            const CharType *_Right
        );
    template<class CharType, class Traits, class Allocator>
        bool operator<= (
            const CharType *_Left,
            const basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        void swap (
            basic_string<CharType, Traits, Allocator>& _Left,
            basic_string<CharType, Traits, Allocator>& _Right
        );
    template<class CharType, class Traits, class Allocator>
        basic_ostream<CharType>& operator<< (
            basic_ostream<CharType>& _OStream,
            const basic_string<CharType, Traits, Allocator>& _Str
        );
    template<class CharType, class Traits, class Allocator>
        basic_istream<CharType>& operator>> (
            basic_istream<CharType>& _IStream,
            basic_string<CharType, Traits, Allocator>& _Str
        );
    template<class CharType, class Traits, class Allocator>
        basic_istream<CharType, Traits>& getline (
            basic_istream<CharType, Traits>& _IStream,
            basic_string<CharType, Traits, Allocator>& _Str
        );
     template<class CharType, class Traits, class Allocator>
        basic_istream<CharType, Traits>& getline (
            basic_istream<CharType, Traits>& _IStream,
            basic_string<CharType, Traits, Allocator>& _Str,
            CharType _Delimiter
        );
     template<class CharType, class Traits, class Allocator>
        basic_istream<CharType, Traits>& getline (
            basic_istream<CharType, Traits>&& _IStream,
            basic_string<CharType, Traits, Allocator>& _Str
        ); 
     template<class CharType, class Traits, class Allocator>
        basic_istream<CharType, Traits>& getline (
            basic_istream<CharType, Traits>&& _IStream,
            basic_string<CharType, Traits, Allocator>& _Str,
            CharType _Delimiter
        );
}  // namespace std

Parámetros

  • CharType
    El parámetro de plantilla que describe el tipo de datos de los valores.

  • rasgos
    El parámetro de plantilla que describe cualquier propiedad de los datos de caracteres de CharType .

  • asignador
    El parámetro de plantilla que describe el objeto almacenado el asignador de memoria.

  • _Str
    basic_string que admite datos de caracteres de CharType .

  • _Val
    Valor que se va a convertir.

  • _Idx
    El valor de índice del primer carácter no.

  • _Base
    Base de número a utilizar.

  • _IStream
    El flujo de entrada que admite datos de caracteres de CharType .

  • _OStream
    La secuencia de salida que admite datos de caracteres de CharType .

  • _Delimiter
    el delimitador de la línea.

  • _Left
    El primer (aplazados) se comparan parámetro, basic_string o los datos de caracteres.

  • _Right
    el segundo (la derecha) compara parámetro, basic_string o los datos de caracteres.

Comentarios

El lenguaje C++ y la biblioteca estándar de C++ admiten dos tipos de cadenas:

  • Matrices de caracteres terminada en null denominadas a menudo cadenas de C.

  • Objetos de clase de plantilla, de basic_stringescrito, que administran todo el char- como argumentos de plantilla.

hd5zecz6.collapse_all(es-es,VS.110).gifTypedefs

string

Un tipo que describe una especialización de la clase de plantilla basic_string con elementos de char escrito como string.

wstring

Un tipo que describe una especialización de la clase de plantilla basic_string con elementos de wchar_t escrito como wstring.

u16string

Un tipo que describe una especialización de la clase de plantilla basic_string basándose en elementos de char16_tescrito.

u32string

Un tipo que describe una especialización de la clase de plantilla basic_string basándose en elementos de char32_tescrito.

hd5zecz6.collapse_all(es-es,VS.110).gifOperadores

operator+

Concatena dos objetos de cadena.

el operador! =

Comprueba si el objeto string en el lado izquierdo del operador no es igual al objeto string en el lado derecho.

operator==

Comprueba si el objeto string en el lado izquierdo del operador es igual al objeto string en el lado derecho.

operator<

Comprueba si el objeto string en el lado izquierdo del operador es menor que el objeto string en el lado derecho.

operator<=

Comprueba si es el objeto string en el lado izquierdo del operador menor o igual que el objeto string en el lado derecho.

operator<<

Una función de plantilla que inserta una cadena en el flujo de salida.

operator>

Comprueba si el objeto string en el lado izquierdo del operador es mayor que el objeto string en el lado derecho.

operator>=

Comprueba si es el objeto string en el lado izquierdo del operador mayor o igual que el objeto string en el lado derecho.

operator>>

Una función de plantilla que dibuja una cadena del flujo de entrada.

hd5zecz6.collapse_all(es-es,VS.110).gifFunciones especializadas de plantilla

intercambio

Cambia las matrices de caracteres de dos cadenas.

stod

Convierte una secuencia de caracteres a double.

stof

Convierte una secuencia de caracteres a float.

stoi

Convierte una secuencia de caracteres a un entero.

stold

Convierte una secuencia de caracteres a long double.

stoll

Convierte una secuencia de caracteres a long long.

stoul

Convierte una secuencia de caracteres a unsigned long.

stoull

Convierte una secuencia de caracteres a unsigned long long.

to_string

Convierte un valor al tipo string.

to_wstring

Convierte un valor en stringancho.

hd5zecz6.collapse_all(es-es,VS.110).gifFunciones

getline

Cadenas de extracto del flujo de entrada línea por línea.

hd5zecz6.collapse_all(es-es,VS.110).gifClases

basic_string Class

una clase de plantilla que describe los objetos que pueden almacenar una secuencia de arbitrario carácter-como objetos.

char_traits Struct

Una clase de plantilla que describe los atributos asociados con un carácter de CharType tipo

hd5zecz6.collapse_all(es-es,VS.110).gifespecializaciones

char_traits<char> Struct

Struct que es una especialización de struct char_traits <CharType> de plantilla a un elemento de charescrito.

char_traits<wchar_t> Struct

Struct que es una especialización de struct char_traits <CharType> de plantilla a un elemento de wchar_tescrito.

char_traits<char16_t> Struct

Struct que es una especialización de struct char_traits <CharType> de plantilla a un elemento de char16_tescrito.

char_traits<char32_t> Struct

Struct que es una especialización de struct char_traits <CharType> de plantilla a un elemento de char32_tescrito.

Requisitos

  • encabezado: <cadena>

  • espacio de nombres: std

Vea también

Referencia

Seguridad para subprocesos de la biblioteca estándar de C++

Otros recursos

Archivos de encabezado