Original Post
Hi guys, I was going through a few samples of msdn . I found this set of code. I am able to partially understand it. I would need ur help to understand the rest. What i didnt understand was the third parameter in the following line.. typedef ostream_iterator > FloatOstreamIt; what is the char_traits stuff? . First parameter is the input to the custom cout Second is the output Atleast am i right with these two? Thanks and Regards Rohith.H.N
Here goes the code
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
#include <string>
using namespace std;
typedef vector < float > FloatArray;
typedef vector < string > StringArray;
typedef ostream_iterator <float, char, char_traits <char> > FloatOstreamIt;
int main ()
{
// a vector of floats
FloatArray rgFA;
// an ostream iterator that outputs a float to cout terminated
// by a space
FloatOstreamIt OstreamIt(cout,"\n");
// Initialize the array to 1,1/2,1/3,...
for (int i=0; i<100; i++) rgFA.push_back(i+1);
// Print the array
copy(rgFA.begin(),rgFA.end(),OstreamIt);
cout << endl;
//// Initialize array of strings
//StringArray rgs;
//rgs.push_back("This ");
//rgs.push_back("is ");
//rgs.push_back("one ");
//rgs.push_back("sentence. ");
//// Concatenate the strings in the array and print the sentence
//cout << "The concatenated vector of strings: "
// << accumulate(rgs.begin(),rgs.end(),string(""))
// << endl;
}