Create ostream_iterator for writing int values to cout : ostream_iterator « File Stream « C++ Tutorial






#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iterator>

int main()
{
   cout << "Enter two integers: ";

   std::istream_iterator< int > inputInt( cin );

   int number1 = *inputInt; 
   ++inputInt;              
   int number2 = *inputInt; 

   std::ostream_iterator< int > outputInt( cout );

   cout << "The sum is: ";
   *outputInt = number1 + number2;
   cout << endl;
   return 0;
}
Enter two integers: 1 2
The sum is: 3








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