1

Possible Duplicate:
How to split a string?

I have a string like this.

a1,b1,a2,b2......

I want a vector of strings like this

a[0] = "a1"
a[1] = "b1"
a[2] = "a2"
a[3] = "b2"

please help me!!

I am not a good programmer, is for a homework, and i only finds this

string sentence = "Something,in,the,way,she,moves...";
istringstream iss(sentence);
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
ostream_iterator<string>(cout, "\n"));

vector<string> tokens;
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
back_inserter<vector<string> >(tokens));

but this only split the words separated by whitespaces.

Community
  • 1
  • 1
COAR
  • 53
  • 3
  • 7
  • 1
    As usual: what have you tried already? – Oliver Charlesworth Jan 26 '11 at 22:02
  • 2
    duplicate - http://stackoverflow.com/questions/236129/how-to-split-a-string – Paula Bean Jan 26 '11 at 22:05
  • 1
    @Paula That's a space-separate string. This is a comma-separated string. There's a big enough gap that either this should remain open or the other question generalised. [This answer](http://stackoverflow.com/questions/236129/how-to-split-a-string/236803#236803) splits on any delimiter. – moinudin Jan 26 '11 at 22:09
  • Voted to re-open, it's not a duplicate because although the result is the same, the input isn't, and you can't use the same technique in the other question as it is. – dreamlax Jan 27 '11 at 00:01

0 Answers0