std::ostreambuf_iterator
來自 cppreference.com
< cpp | 迭代器 (iterator)
定義於標頭檔案 <iterator> |
||
template< class CharT, class Traits = std::char_traits<CharT> > class ostreambuf_iterator |
(C++17 前) | |
template< class CharT, class Traits = std::char_traits<CharT> > class ostreambuf_iterator; |
(C++17 起) | |
std::ostreambuf_iterator
是一個單趟 LegacyOutputIterator,它將連續字元寫入構造時使用的 std::basic_streambuf 物件。實際的寫入操作在迭代器(無論是否解引用)被賦值時執行。遞增 std::ostreambuf_iterator
是一個空操作。
在典型的實現中,std::ostreambuf_iterator
的唯一資料成員是一個指向關聯 std::basic_streambuf
的指標和一個布林標誌,指示是否已達到檔案結束條件。
目錄 |
[編輯] 成員型別
成員型別 | 定義 | ||||
iterator_category
|
std::output_iterator_tag | ||||
value_type
|
void | ||||
difference_type
|
| ||||
pointer
|
void | ||||
reference
|
void | ||||
char_type
|
CharT
| ||||
traits_type
|
特性
| ||||
streambuf_type
|
std::basic_streambuf<CharT, Traits> | ||||
ostream_type
|
std::basic_ostream<CharT, Traits> |
成員型別 |
(C++17 前) |
[編輯] 成員函式
構造一個新的 ostreambuf_iterator (public member function) | |
(解構函式) (隱式宣告) |
銷燬一個 ostreambuf_iterator (public member function) |
向關聯的輸出序列寫入一個字元 (public member function) | |
無操作 (public member function) | |
無操作 (public member function) | |
測試輸出是否失敗 (public member function) |
[編輯] 示例
執行此程式碼
#include <algorithm> #include <iostream> #include <iterator> #include <string> int main() { std::string s = "This is an example\n"; std::copy(s.begin(), s.end(), std::ostreambuf_iterator<char>(std::cout)); }
輸出
This is an example
[編輯] 參閱
從std::basic_streambuf讀取的輸入迭代器 (class template) | |
寫入std::basic_ostream的輸出迭代器 (class template) |