vendredi 15 mai 2015

Transform a vector of int to a vector of str

I'm trying to convert a vector<int> to a vector<string>. Using std::transform I used std::to_string to convert the int to string but I keep getting an error. Here's my code

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>

int main(){
    std::vector<int> v_int;
    std::vector<std::string> v_str;

    for(int i = 0;i<5;++i)
        v_int.push_back(i);

    v_str.resize(v_int.size());
    std::transform(v_int.begin(),v_int.end(),v_str.begin(),std::to_string);
}

but I'm getting this error

 no matching function for call to 'transform'
        std::transform(v_int.begin(),v_int.end(),v_str.begin(),std::to_string);
        ^~~~~~~~~~~~~~
/Applications/http://ift.tt/1QPIKXJ: note: 
      candidate template ignored: couldn't infer template argument
      '_UnaryOperation'
transform(_InputIterator __first, _InputIterator __last, _OutputIterato...
^
/Applications/http://ift.tt/1IFRWLo: note: 
      candidate function template not viable: requires 5 arguments, but 4 were
      provided
transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputItera...

Aucun commentaire:

Enregistrer un commentaire