Think about this logically.
You need to extract 4 characters, get their numerical value, and push them onto a vector.
Code:
#include <vector>
#include <string>
#include <iostream>
#include <cstdlib>
std::vector<int> fill_vec(const std::string &input);
int main(int argc, char* argv[])
{
std::string mystr("13345678198734568765");
std::vector<int> returned = fill_vec(mystr);
for (int i = 0; i < returned.size(); i++)
std::cout<<returned[i]<<std::endl;
return 0;
}
std::vector<int> fill_vec(const std::string &input)
{
typedef std::string::size_type st;
std::string temp;
std::vector<int> intvec;
for (st index = 0; index < input.size(); index += 4)
{
for (int i = index; i < index+4; i++)
temp += input[i];
intvec.push_back(atoi(temp.c_str()));
temp.erase();
}
return intvec;
}
It's 3AM
Here's a sloppy, yet functional solution. input must be a multiple of 4.