parse string to vector of int
You can use std::stringstream
. You will need to #include <sstream>
apart from other includes.
#include <sstream>
#include <vector>
#include <string>
std::string myString = "10 15 20 23";
std::stringstream iss( myString );
int number;
std::vector<int> myNumbers;
while ( iss >> number )
myNumbers.push_back( number );
std::string myString = "10 15 20 23";
std::istringstream is( myString );
std::vector<int> myNumbers( ( std::istream_iterator<int>( is ) ), ( std::istream_iterator<int>() ) );
Or instead of the last line if the vector was already defined then
myNumbers.assign( std::istream_iterator<int>( is ), std::istream_iterator<int>() );