basic_stringstream 類別
描述物件,該物件會使用類別 的資料流程緩衝區,控制元素和編碼物件的插入和擷取,basic_stringbuf < Elem 、 Tr 、 。 Alloc
>
語法
template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem>>
class basic_stringstream : public basic_iostream<Elem, Tr>
參數
Alloc
配置器類別。
Elem
字串之基本項目的類型。
Tr
字元特性是在字串的基本項目上特製化。
備註
類別範本描述一個 物件,該物件會使用類別 basic_stringbuf的資料流程緩衝區, < 控制元素和編碼物件的插入和擷取,其類型為 的 >Alloc
元素 Elem
,其字元特性是由 類別所決定,以及其元素是由 類別 Tr
的配置 Alloc
器所配置。 物件會儲存類別的物件basic_stringbuf < Elem 、 Tr 、 Alloc
> 。
建構函式
建構函式 | 描述 |
---|---|
basic_stringstream | 建構類型 basic_stringstream 的物件。 |
Typedefs
類型名稱 | 描述 |
---|---|
allocator_type | 此類型是範本參數 Alloc 的同義字。 |
成員函式
成員函數 | 描述 |
---|---|
rdbuf | 傳回 類型 pointer 之預存資料流程緩衝區的位址,以 basic_stringbuf Elem < 、 。 Tr Alloc > |
str | 設定或取得字串緩衝區中的文字,而不需要變更寫入位置。 |
需求
Header: < sstream>
命名空間:std
basic_stringstream::allocator_type
此類型是範本參數 Alloc
的同義字。
typedef Alloc allocator_type;
basic_stringstream::basic_stringstream
建構類型 basic_stringstream
的物件。
explicit basic_stringstream(ios_base::openmode _Mode = ios_base::in | ios_base::out);
explicit basic_stringstream(const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode _Mode = ios_base::in | ios_base::out);
參數
_模式
ios_base::openmode 中的其中一個列舉。
str
basic_string
類型的物件。
備註
第一個建構函式會呼叫 basic_iostream(sb),以初始化基類,其中 sb
是類別 basic_stringbuf < Elem 、 Tr 、 Alloc
> 的預存物件。 它也會藉由呼叫 basic_stringbuf Elem , Tr , Alloc
> 來初始化 sb
。 _Mode
<
第二個建構函式會藉由呼叫 basic_iostream( sb) 初始化基底類別。 它也會藉由呼叫 basic_stringbuf < Elem 、Tr 、 >Alloc
(_ Str 、 _Mode
) 來初始化 sb
。
basic_stringstream::rdbuf
傳回類型指標的預存資料流程緩衝區 位址,basic_stringbuf < Elem 、Tr 、 。 Alloc
>
basic_stringbuf<Elem, Tr, Alloc> *rdbuf() const;
傳回值
類型為 basic_stringbuf < Elem 、 Tr 、 Alloc
> 的預存資料流程緩衝區 pointer
位址。
範例
如需使用 rdbuf
的範例,請參閱 basic_filebuf:: close。
basic_stringstream::str
設定或取得字串緩衝區中的文字,而不需要變更寫入位置。
basic_string<Elem, Tr, Alloc> str() const;
void str(
const basic_string<Elem, Tr, Alloc>& _Newstr);
參數
_Newstr
新字串。
傳回值
傳回類別 basic_string < Elem , Tr , 的物件, Alloc
> 其受控制序列是 所 *this
控制之序列的複本。
備註
第一個成員函式會傳 回 rdbuf - > str 。 第二個成員函式會呼叫 rdbuf
- > str ( _Newstr
。
範例
如需使用 str
的範例,請參閱 basic_stringbuf::str 。
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應