0

Possible Duplicate:
How to split a string in C++?

I need split my string as

1. StackOverflow
2. Sky
3. CLOUD
4. Sun
11. Moon
12.Star

into

StackOverflow
sky
cloud
sun
moon
star.

How to do in C++, in vb , it shoud be like this

string test= 1. StackOverflow
 string spliteed = test.split(.)

no idea in c++ is how. Thx for advice

Community
  • 1
  • 1
  • I'd agree this is pretty much a duplicate of the above referenced question. –  Mar 06 '12 at 04:00
  • Seems like you want the numbers from the string extracted? Also, your _vb_ example doesn't look right, why is `test=1.sky` your string starts with the letters `1.Stackoverflow`? – gideon Mar 06 '12 at 04:01

2 Answers2

0

It seems your strings are already splitted and you are just removing numerals. If that is the case use Boost Regex (regular expressions) else for splitting the string you can use boost split function. Boost is a set of libraries in c++. Do Google it.

Yavar
  • 11,883
  • 5
  • 32
  • 63
0

You can use stringstream class to consume the integer and the dot:

#include <string>
#include <iostream>
#include <sstream>
using namespace std;

int main(int argc, char* argv[])
{
    string str = "1. sky";
    stringstream sstr(str);
    int i;
    char c;
    string s;

    sstr >> i >> c >> s;
    cout << s << endl;

    return 0;
}
Donotalo
  • 12,748
  • 25
  • 83
  • 121
  • Thx. between if string str= "1. SKY BLUE" the s will be equal to sky. how to become sky blue – Raymond Wong Mar 06 '12 at 04:11
  • well, you can continuously read: `sstr >> i >> c; while(sstr >> s) { // do something with s }`. the loop will terminate when all words are extracted. – Donotalo Mar 06 '12 at 05:27