共用方式為


<string>

定義容器樣板類別 basic_string 和各種支援的樣板。

如需 basic_string 的詳細資訊,請參閱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

參數

  • CharType
    描述字元資料型別的樣板參數。

  • 特性
    描述 CharType 字元資料之所有屬性的樣板參數。

  • 配置器
    描述的記憶體配置器物件中的樣板參數。

  • _Str
    支援 CharType 字元資料的 basic_string

  • _Val
    要轉換的值。

  • _Idx
    第一個未轉換字元的索引值。

  • _Base
    使用中的基底。

  • _IStream
    支援 CharType 字元資料的輸入資料流。

  • _OStream
    支援 CharType 字元資料的輸出資料流。

  • _Delimiter
    行分隔符號。

  • _Left
    第一個 (保留) 比較參數, basic_string 或字元資料。

  • _Right
    第二個 (右側) 比較參數, basic_string 或字元資料。

備註

C++ 語言和 Standard C++ 程式庫支援字串型別有兩種:

  • 通常稱為 C 字串是以 Null 結尾的字元陣列。

  • 樣板類別物件,型別 basic_string,處理所有 char類似的樣板引數。

hd5zecz6.collapse_all(zh-tw,VS.110).gifTypedef

string

描述 basic_string 類別樣板特製化的型別 char 項目做為 string的型別。

wstring

描述 basic_string 類別樣板特製化的型別 wchar_t 項目做為 wstring的型別。

u16string

描述 basic_string 樣板類別的特製化的型別會根據型別 char16_t的項目。

u32string

描述 basic_string 樣板類別的特製化的型別會根據型別 char32_t的項目。

hd5zecz6.collapse_all(zh-tw,VS.110).gif運算子

operator+

串連兩個字串物件。

運算子! =

測試,如果左側的字串物件等於右邊的字串物件不相等。

運算子==

測試,如果左側的字串物件等於右邊的字串物件。

operator<

測試,如果左側的字串物件小於至右邊的字串物件。

operator<=

測試,如果左側的字串物件小於或等於右邊的字串物件。

operator<<

字串插入輸出資料流的樣板函式。

operator>

測試,如果左側的字串物件大於至右邊的字串物件。

operator>=

測試,如果左側的字串物件大於或等於右邊的字串物件。

operator>>

擷取輸入資料流的字串之樣板函式。

hd5zecz6.collapse_all(zh-tw,VS.110).gif特製化函式樣板

交換

交換兩個字串的字元陣列。

stod

將字元序列轉換成 double.

stof

將字元序列轉換成 float。

stoi

將字元序列轉換成整數。

stold

將字元序列轉換成 long double。

stoll

將字元序列轉換成 long long。

stoul

將字元序列轉換成 unsigned long。

stoull

將字元序列轉換成 unsigned long long。

to_string

將值轉換為 string

to_wstring

將值轉換為 string寬度。

hd5zecz6.collapse_all(zh-tw,VS.110).gif功能

getline

從逐行輸入資料流中擷取字串。

hd5zecz6.collapse_all(zh-tw,VS.110).gif類別

basic_string Class

描述物件可以儲存任意字元類似的物件序列的樣板類別。

char_traits Struct

描述屬性與型別 CharType 字元的樣板類別

hd5zecz6.collapse_all(zh-tw,VS.110).gif特製化

char_traits<char> Struct

範本是結構 char_traits<CharType> 特製化的型別 char項目的結構。

char_traits<wchar_t> Struct

範本是結構 char_traits<CharType> 特製化的型別 wchar_t項目的結構。

char_traits<char16_t> Struct

範本是結構 char_traits<CharType> 特製化的型別 char16_t項目的結構。

char_traits<char32_t> Struct

範本是結構 char_traits<CharType> 特製化的型別 char32_t項目的結構。

需求

  • 標題: <string>

  • 命名空間: std

請參閱

參考

在標準 C++ 程式庫中的執行緒安全

其他資源

標頭檔