samedi 17 août 2019

How to fix ostream_iterator conversion problem?

I was studying ' unique_copy( forwrdIt first,forwrdIt last, forwrdIt result) ' and i tried to pass result as : 'ostream_iterator(cout, " ") ' but it threw an error 'no known conversion for argument 1 from ‘std::ostream_iterator’ to ‘__gnu_cxx::__normal_iterator >&&'. i can make another vector and then i can insert it's iterator. Why so?

i can make another vector and then i can insert it's begin() iterator. Why so?

vector<int> v = {1,2,3,1,2,2,2,3,4,5,5,5,6,7,7,8,1,1};
vector<int>::iterator ip;
    ip = unique_copy(v.begin(), v.end(), ostream_iterator<int>(cout, ","));


1 2 3 1 2 3 4 5 6 7 8 1

Aucun commentaire:

Enregistrer un commentaire