| | |
STL, istream_iterator class doesn't compileq
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 23
Reputation:
Solved Threads: 0
I need help trying to compile and test this code, but I keep getting the error: template is incomplete, can not parse field.
Here is my code:
can someone tell me what I'm doing wrong and how do I make the template complete?
Thank You,
Here is my code:
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<iterator> #include<vector> #include<algorithm> using namespace std; template <class T> class my_istream_iterator { public: typedef charT char_type; typedef traitsT traits_type; typedef basic_istream<charT, traitsT> istream_type; typedef input_iterator_tag iterator_category; typedef T value_type; typedef diff difference_type; typedef const T* pointer; typedef const T& reference; my_istream_iterator():is(0), pred(false) {} my_istream_iterator( istream_type &s ):is(&s) { read_next();} reference operator*() const { return current; } pointer operator->() const { return &(operator*()); } my_istream_iterator& operator++() { read_next(); return *this; } my_istream_iterator operator++(int) { my_istream_iterator temp = *this; read_next(); return temp; } bool my_equal(const my_istream_iterator &x) const { return (pred == x.pred) && (!pred || is == x.is); } private: T current; istream_type *is; bool pred; void read_next() { if( is == NULL || (is >> current)) is = NULL; } }; template<class T> bool operator==(const my_istream_iterator<T> &is1, const my_istream_iterator<T> &is2) { return is1.my_equal(is2); } template<class T> bool operator!=(const my_istream_iterator<T> &is1, const my_istream_iterator<T> &is2) { return !is.my_equal(is2); } main() { vector<int> v; my_istream_iterator<vector<int> > is(cin); my_istream_iterator<vector<int> > eof; copy(is, eof, back_inserter(v)); copy(v.begin(), v.end(), ostream_iterator<int>(cout, "\t")); cout << endl; }
can someone tell me what I'm doing wrong and how do I make the template complete?
Thank You,
![]() |
Similar Threads
- help:stl vector of user defined objects (C)
- Is there a 'parent' stl container class? (C++)
- Help with < (less than) operator on classes (C++)
Other Threads in the C++ Forum
- Previous Thread: tolower()'d cstrings in conditional statements
- Next Thread: Pascal -> C++; Binary, convert?
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






