dimanche 6 mai 2018

output vector

This section of code gives an error:

template <class T>
void print_vector(vector<T>& v, string sep)
{
    std::ostream_iterator<vector<T>> ostr_it(std::cout, sep) ;
    std::copy(begin(v), end(v), ostr_it);
}

main.cpp:17:38: error: no matching constructor for initialization of    'std::ostream_iterator<vector<float> >'
std::ostream_iterator<vector<T>> ostr_it(std::cout, sep) ;

I am confused because if I call it directly there is no error:

vector<float> result(elements);
std::copy(begin(result), end(result), ostream_iterator<float>(cout, ", "));

What is wrong? ^ ~~~~~~~~~~~~~~

Aucun commentaire:

Enregistrer un commentaire