error when using input iterator

Hi all. I am a newbie and trying to use stl input iterator. Here is the code

std::istream_iterator<char, ptrdiff_t> in (std::cin);

and getting following error. Can any one please help me with this.
I am using Microsoft Visual studio 2005 pro, Vista.

1
2
3
4
5
6
7
8
9
10
11
12
 error C2664: 'std::istream_iterator<_Ty,_Elem>::istream_iterator(std::basic_istream<_Elem,_Traits> &)' : cannot convert parameter 1 from 'std::istream' to 'std::basic_istream<_Elem,_Traits> &'
1>        with
1>        [
1>            _Ty=char,
1>            _Elem=ptrdiff_t,
1>            _Traits=std::char_traits<ptrdiff_t>
1>        ]
1>        and
1>        [
1>            _Elem=ptrdiff_t,
1>            _Traits=std::char_traits<ptrdiff_t>
1>    
]
The second template parameter defines the char type of the input stream you are using, for std::cin that is 'char' which is the default parameter. So you might try
std::istream_iterator<char> in(std::cin);
If you want to overwrite the distance type, you have to use the 4th template parameter (but since the default already is ptrdiff_t, there would be no point in that).

BTW, while std::istream_iterator is a model for the concept Input Iterator, it is not "the" input iterator.

Hope that helps.
Lovely. Thanks mate for the quick reply.
Appreciate it.
Topic archived. No new replies allowed.