I have a vector of strings. Need help figuring out how to convert it into vector of integers in order to be able to work with it arithmetically. Thanks!
#include
#include
#include
#include
#include
#include
using namespace std;
int stringToInteger(const std::string& s)
{
return boost::lexical_cast(s);
}
int main(int /*argc*/, char* /*argv*/[])
{
vector vectorOfStrings;
// ..
vector vectorOfIntegers;
std::transform(vectorOfStrings.begin(), vectorOfStrings.end(), std::back_inserter(vectorOfIntegers), stringToInteger);
// ..
}
You can replace the implementation of stringToInteger(..) with your preferred conversion function.