1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
// source
char mData[] = "20,1,1,12,21,11,23,2,2,21,1,1,0,30,0,0,0,1,1,1,"
"2,3,3,13,1,1,3,3,21,11,1,22,3,2,12,12,13,2,2,2,"
"32,3,33,3,33,23,32,31,1,21,2,2,3,1,0,1,2,3,3,3";
// destination
vector<int> container;
// tokenize string using ',' as a delimiter
string token;
stringstream sin( mData );
while( getline( sin, token, ',' ) )
{
// convert each string token into an integer
int number;
stringstream converter( token );
converter >> number;
// add integer to container
container.push_back( number );
}
// dump contents of container to stdout
copy( container.begin(), container.end(), ostream_iterator<int>( cout, " " ) );
cout << endl;
return 0;
}
|