std::ostream_iterator<T,CharT,Traits>::operator=
來自 cppreference.com
< cpp | 迭代器 | ostream 迭代器
ostream_iterator& operator=( const ostream_iterator& ); |
(1) | |
ostream_iterator& operator=( const T& value ); |
(2) | |
1) 複製賦值運算子。賦值 other 的內容。
2) 將 value 插入到關聯流中,然後插入分隔符(如果構造時指定了分隔符)。
如果 out_stream
是指向關聯的 std::basic_ostream 的指標,並且 delim
是構造此物件時指定的分隔符,則效果等同於:
*out_stream << value;
if (delim != 0)
*out_stream << delim;
return *this;
目錄 |
[編輯] 引數
value | - | 要插入的物件 |
[編輯] 返回值
*this
[編輯] 注意
T
可以是任何具有使用者定義的 operator<<
的類。
在 C++20 之前,複製賦值運算子的存在依賴於已棄用的隱式生成。
[編輯] 示例
執行此程式碼
#include <iostream> #include <iterator> int main() { std::ostream_iterator<int> i1(std::cout, ", "); *i1++ = 1; // usual form, used by standard algorithms *++i1 = 2; i1 = 3; // neither * nor ++ are necessary std::ostream_iterator<double> i2(std::cout); i2 = 3.14; std::cout << '\n'; }
輸出
1, 2, 3, 3.14