Partager via


ostream_iterator::operator=

Assignment operator used to implement the output_iterator expression *i = x for writing to an output stream.

ostream_iterator<Type, CharType, Traits>& operator=(
   const Type& _Val
);

Parameters

  • _Val
    The value of the object of type Type to be inserted into the output stream.

Return Value

The operator inserts _Val into the output stream associated with the object, followed by the delimiter specified in the ostream_iterator constructor (if any), and then returns a reference to the ostream_iterator.

Remarks

The requirements for an output iterator that the ostream_iterator must satisfy require only the expression *ii = t be valid and says nothing about the operator or the operator= on their own. This member operator returns *this.

Example

// ostream_iterator_op_assign.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   // ostream_iterator for stream cout
   // with new line delimiter
   ostream_iterator<int> intOut ( cout , "\n" );

   // Standard iterator interface for writing
   // elements to the output stream
   cout << "Elements written to output stream:" << endl;
   *intOut = 10;
   intOut++;      // No effect on iterator position
   *intOut = 20;
   *intOut = 30;
}
Elements written to output stream:
10
20
30

Requirements

Header: <iterator>

Namespace: std

See Also

Reference

ostream_iterator Class

Standard Template Library

Other Resources

ostream_iterator Members