basic_ostringstream 類別
描述物件,控制將專案和編碼物件插入類別 的資料流程緩衝區,basic_stringbuf < Elem 、 Tr 、 。 Alloc
>
語法
template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem>>
class basic_ostringstream : public basic_ostream<Elem, Tr>
參數
Alloc
配置器類別。
Elem
字串之基本項目的類型。
Tr
字元特性是在字串的基本項目上特製化。
備註
類別描述一個物件,可控制將專案和編碼物件插入資料流程緩衝區,其 Elem
類型為 的專案,其字元特性是由 類別所決定,而其專案是由 類別 Tr
Alloc
的配置器所配置。 物件會儲存類別的物件basic_stringbuf < Elem 、 Tr 、 Alloc
> 。
建構函式
建構函式 | 描述 |
---|---|
basic_ostringstream | 建構類型 basic_ostringstream 的物件。 |
Typedefs
類型名稱 | 描述 |
---|---|
allocator_type | 此類型與範本參數 Alloc 同義。 |
成員函式
成員函數 | 描述 |
---|---|
rdbuf | 傳回 類型 pointer 之預存資料流程緩衝區的位址,以 basic_stringbuf Elem < 、 。 Tr Alloc > |
str | 設定或取得字串緩衝區中的文字,而不需要變更寫入位置。 |
需求
Header: < sstream>
命名空間:std
basic_ostringstream::allocator_type
此類型與範本參數 Alloc 同義。
typedef Alloc allocator_type;
basic_ostringstream::basic_ostringstream
建構 basic_ostringstream 類型的物件。
explicit basic_ostringstream(ios_base::openmode _Mode = ios_base::out);
explicit basic_ostringstream(const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode _Mode = ios_base::out);
參數
_模式
ios_base::openmode 中的其中一個列舉。
str
basic_string
類型的物件。
備註
第一個建構函式會呼叫 basic_ostream( sb )
來初始化基類,其中 sb
是 類別 basic_stringbuf< Elem, Tr, Alloc>
的預存物件。 它也會藉由呼叫 basic_stringbuf< Elem, Tr, Alloc>( _Mode | ios_base::out )
來初始化 sb
。 如需詳細資訊,請參閱 basic_ostream
和 basic_stringbuf
。
第二個建構函式會藉由呼叫 basic_ostream( sb )
初始化基底類別。 它也會藉由呼叫 basic_stringbuf< Elem, Tr, Alloc >( str, _Mode | ios_base::out )
來初始化 sb
。
basic_ostringstream::rdbuf
傳回 類型 pointer
之預存資料流程緩衝區的位址,以 basic_stringbuf < Elem 、Tr 、。 Alloc
>
basic_stringbuf<Elem, Tr, Alloc> *rdbuf() const;
傳回值
儲存資料流程緩衝區的位址,類型 pointer
為 basic_stringbuf < Elem 、Tr 、 Alloc
> 。
備註
成員函式會將 類型的 pointer
預存資料流程緩衝區位址傳回至 Elem < 、Tr 、 Alloc
> basic_stringbuf。
範例
如需使用 rdbuf
的範例,請參閱 basic_filebuf:: close。
basic_ostringstream::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 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應