ostream_iterator::ostream_iterator
建構初始化並分隔寫入輸出資料流中的 ostream_iterator 。
ostream_iterator(
ostream_type& _Ostr
);
ostream_iterator(
ostream_type& _Ostr,
const CharType* _Delimiter
);
參數
_Ostr
型別要重複的 ostream_iterator::ostream_type 輸出資料流。_Delimiter
要插入至的值之間的輸出資料流的分隔符號。
備註
第一個建構函式會初始化 &_Ostr的輸出資料流的指標。 分隔符號字串指標指定空字串。
第二個建構函式會初始化 &_Ostr 的輸出資料流指標和 _Delimiter的分隔符號字串指標。
範例
// ostream_iterator_ostream_iterator.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
// ostream_iterator for stream cout
ostream_iterator<int> intOut ( cout , "\n" );
*intOut = 10;
intOut++;
*intOut = 20;
intOut++;
int i;
vector<int> vec;
for ( i = 1 ; i < 7 ; ++i )
{
vec.push_back ( i );
}
// Write elements to standard output stream
cout << "Elements output without delimiter: ";
copy ( vec.begin ( ), vec.end ( ),
ostream_iterator<int> ( cout ) );
cout << endl;
// Write elements with delimiter " : " to output stream
cout << "Elements output with delimiter: ";
copy ( vec.begin ( ), vec.end ( ),
ostream_iterator<int> ( cout, " : " ) );
cout << endl;
}
需求
標題: <iterator>
命名空間: std