Udostępnij za pośrednictwem


<string>

Definiuje klasę szablonu pojemnika basic_string i różnych szablonów pomocniczych.

Więcej informacji o basic_string, zobaczbasic_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

Parametry

  • CharType
    Parametr szablonu, który opisuje typ danych znak.

  • Cechy
    Parametr szablonu, który opisuje wszystkie właściwości CharType znaków danych.

  • Program przydzielania
    Parametr szablonu opisującą obiekt przydzielania pamięci przechowywane.

  • _Str
    basic_string Obsługującego CharType znaków danych.

  • _Val
    Wartość do konwersji.

  • _Idx
    Wartość indeksu pierwszego znaku nieprzekonwertowane.

  • _Base
    Bazowy numer, aby użyć.

  • _IStream
    Strumień wejściowy, który obsługuje CharType znaków danych.

  • _OStream
    Strumienia wyjściowego, które obsługuje CharType znaków danych.

  • _Delimiter
    Ogranicznik linii.

  • _Left
    Pierwszy (po lewej) albo porównać parametr, basic_string lub danych znakowych.

  • _Right
    Drugiej (prawej) albo porównać parametr, basic_string lub danych znakowych.

Uwagi

Języka C++ i standardowa biblioteka języka C++ obsługuje dwa typy ciągów:

  • Często określane jako ciągi c tablice zakończonego znakiem null.

  • Szablon klasy obiektów, typu basic_string, które obsługują wszystkie char-jak szablon argumentów.

hd5zecz6.collapse_all(pl-pl,VS.110).gifDefinicje TypeDef

ciąg

Typ, który opisuje specjalizacji szablonu klasy basic_string z elementami typu char jako string.

wstring

Typ, który opisuje specjalizacji szablonu klasy basic_string z elementami typu wchar_t jako wstring.

u16string

Typ, który opisuje specjalizacji szablonu klasy basic_string oparte na elementy typu char16_t.

u32string

Typ, który opisuje specjalizacji szablonu klasy basic_string oparte na elementy typu char32_t.

hd5zecz6.collapse_all(pl-pl,VS.110).gifOperatory

operator +

Łączy dwa obiekty ciąg.

operator! =

Testy, jeśli obiekt string po lewej stronie operatora nie jest równa obiekt string po prawej stronie.

operator ==

Testy, jeśli obiekt string po lewej stronie operatora jest równa obiekt string po prawej stronie.

operator <

Badania, jeśli obiekt string po lewej stronie operatora jest mniejsza niż obiekt string po prawej stronie.

operator < =

Testy, jeśli ciąg obiektu po lewej stronie operatora jest mniejsza lub równa obiekt string po prawej stronie.

operator <<

Funkcja szablonu, który wstawia ciąg do strumienia wyjściowego.

operator >

Testy, jeśli obiekt string po lewej stronie operatora jest większa niż obiekt string po prawej stronie.

operator > =

Testy, jeśli obiekt string po lewej stronie operatora jest większa niż lub równa obiekt string po prawej stronie.

operator >>

Funkcję szablonu wyciągów ze strumienia wejściowego ciągu.

hd5zecz6.collapse_all(pl-pl,VS.110).gifWyspecjalizowane funkcje szablonu

Zamień

Wymiany tablice znaków dwóch ciągów.

stod

Konwertuje sekwencję znaków dodouble.

stof

Konwertuje sekwencję znaków do float.

stoi

Konwertuje całkowitą sekwencję znaków.

stold

Konwertuje sekwencję znaków do long double.

stoll

Konwertuje sekwencję znaków do long long.

stoul

Konwertuje sekwencję znaków do unsigned long.

stoull

Konwertuje sekwencję znaków do unsigned long long.

to_string

Konwertuje wartość na string.

to_wstring

Konwertuje wartość na szerokiego string.

hd5zecz6.collapse_all(pl-pl,VS.110).gifFunkcje

getline

Wyodrębnij ciągi ze strumienia wejściowego linii.

hd5zecz6.collapse_all(pl-pl,VS.110).gifKlasy

basic_string Class

Klasy szablonu, który opisuje obiekty, można przechowywać sekwencji dowolnego znaku podobnych obiektów.

char_traits Struct

Klasa szablonu, która opisuje atrybuty skojarzone z znaku typu CharType

hd5zecz6.collapse_all(pl-pl,VS.110).gifDziedziny specjalizacji

char_traits<char> Struct

Struct, który jest struktura szablonu char_traits<CharType> do elementu typu char.

char_traits<wchar_t> Struct

Struct, który jest struktura szablonu char_traits<CharType> do elementu typu wchar_t.

char_traits<char16_t> Struct

Struct, który jest struktura szablonu char_traits<CharType> do elementu typu char16_t.

char_traits<char32_t> Struct

Struct, który jest struktura szablonu char_traits<CharType> do elementu typu char32_t.

Wymagania

  • Nagłówek: <string>

  • Obszar nazw: std

Zobacz też

Informacje

Bezpieczeństwo wątków w standardowa biblioteka języka C++

Inne zasoby

Pliki nagłówków