Processing String Streams

Hi I am trying to extract a number and a string of letters then individually process that string but i am having trouble with the string stream.
My input is (11,LL) (7,LLL) (8,R)
and basically I want to take out the: 11 LL 7 LLL 8 R
if anyone could help me that would be great thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

int main(){
string text = "";
char p1;
char p2;
char c;
int num = 0;
string dir;

while(cin >> text)
{
stringstream ss(text);
ss >> p1 >> num >> c >> dir >> p2;


cout << p1 << num << c << dir << p2<<endl;

}

}
anyone??
I think that stringstream wouldn't be too helpful here. Better use the find() function of string at this point.
I want to extract the integer and string between the ( ) is there an easier way of doing this?
You can use getline( stream, string, delimiter ). You can tokenize by ) to get the three groups in ()'s, then tokenize by , and then extract the values.
If the input is that regular, just tokenize sequentially:

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
vector <int>     nums;
vector <string> strs;

string text;
while (getline( cin, text ))
  {
  istringstream ss( text );
  string s;
  int    n;

  while (true)
    {
    // Skip up to '('
    getline( ss, s, '(' );

    // Get the number and skip ','
    ss >> n;
    getline( ss, s, ',' );

    // Get the string and skip ')'
    getline( ss, s, ')' );

    // Were the gets successful?
    if (!ss) break;

    // save them
    nums.push_back( n );
    strs.push_back( s );
    }
  }

The commentary is for your understanding.

Hope this helps.
Thank you Duoas! that helped a lot!
for my input it is multiple lines but i want to stop getting the input when it reaches this ()
for example my input is:
(11,LL)(7,LLL)(8,R)(5,) (4,L) (13,RL)
(2,LLR) (1,RRR) (4,RR) ()

(3,L) (4,R) ()

I want to process all of the integers and numbers b4 the () then start start over with the
(3,L) (4,R) () .
any ideas?
Er, well, that complicates it. You'll have to do as moorecm suggests, and tokenize on just '(' and ')'. Once you have a string that represents everything between two parentheses, you'll have to tokenize it. If the string is empty, then you know you're done.

Good luck!
Topic archived. No new replies allowed.