Use ostream_iterator : ostream_iterator « File Stream « C++ Tutorial






#include <iostream>
#include <iterator>
using namespace std;

int main()
{
  ostream_iterator<char> out_it(cout);

  *out_it = 'X';
  out_it++;
  *out_it = 'Y';
  out_it++;
  *out_it = ' ';

  char str[] = "C++ Iterators are powerful.\n";
  char *p = str;
  
  while(*p) *out_it++ = *p++;

  ostream_iterator<double> out_double_it(cout);
  *out_double_it = 187.23;  
  out_double_it++;
  *out_double_it = -102.7;  

  return 0;
}
XY C++ Iterators are powerful.
187.23-102.7








12.12.ostream_iterator
12.12.1.Use ostream_iterator
12.12.2.Create ostream_iterator for writing int values to cout
12.12.3.Use ostream_iterator and copy to display collection content
12.12.4.transform algorithm with ostream_iterator