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の出力ストリーム ポインターを初期化します。 区分線の文字列ポインターは空の文字列を指定します。
2 番目のコンストラクターは &_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;
}
必要条件
ヘッダー: の <反復子>
名前空間: std