分享方式:


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 、AllocTr>Elem<
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_stringbufElem, Tr>Alloc 來初始化 。 _Mode<sb

第二個建構函式會藉由呼叫 basic_iostream( sb) 初始化基底類別。 它也會藉由呼叫 basic_stringbuf<Elem、TrAlloc>(_ 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<ElemTr, 的物件,Alloc>其受控制序列是 所*this控制之序列的複本。

備註

第一個成員函式會傳 回 rdbuf ->str。 第二個成員函式會呼叫 rdbuf ->str_Newstr

範例

如需使用 str的範例,請參閱 basic_stringbuf::str

另請參閱

C++ 標準程式庫中的執行緒安全
iostream 程式設計
iostreams 慣例