I have a vector
of strings
and an empty vector
of int
:
vector<string> ints_as_strings;
vector<int> ints_as_ints;
Goal is to transform the former into the latter.
std::transform
with a lambda works:
std::transform(ints_as_strings.begin(),
ints_as_strings.end(),
back_inserter(ints_as_ints),
[](const string& s) {return std::stoi(s);});
However I just want to use std::stoi
.
Passing the address of my mystoi
function works:
int mystoi(string s) {return stoi(s);}
std::transform(ints_as_strings.begin(),
ints_as_strings.end(),
back_inserter(ints_as_ints),
&mystoi);
However, directly passing the address of std::stoi
doesn't work.
Is this on account of the extra parameters (for which, however, default values are provided)?