tags:

views:

44

answers:

2

here is code

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iterator>
using std::vector;
using std::string;
using std::cout;
using std::cin;
using std::ostream_iterator;
using std::cout;

int main(){
     vector <string> me;
     string s;
     while ((cin>>s) && s!="end")
         me.push_back(s);

     std::copy(me.begin(),me.end(),
         std::ostream_iterator(cout,"\n"));



     return 0;
}

but here is mistakes

1>------ Build started: Project: stl_implementation, Configuration: Debug Win32 ------
1>  implementation.cpp
1>c:\users\david\documents\visual studio 2010\projects\stl_implementation\implementation.cpp(21): error C2955: 'std::ostream_iterator' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\iterator(516) : see declaration of 'std::ostream_iterator'
1>c:\users\david\documents\visual studio 2010\projects\stl_implementation\implementation.cpp(21): error C2955: 'std::ostream_iterator' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\iterator(516) : see declaration of 'std::ostream_iterator'
1>c:\users\david\documents\visual studio 2010\projects\stl_implementation\implementation.cpp(21): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
+2  A: 

ostream_iterator needs a template argument; use ostream_iterator<string> in this case.

Philipp
A: 

The ostream_iterator is implemented as:

namespace std {
   template <class T,
             class charT = char,
             class traits = char_traits<charT> >
    class ostream_iterator; 
}

The 2nd and 3rd arguments are optional, but the first is necessary. You have to use it as Philipp mentioned.

DumbCoder