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
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.
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 );
}
}
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.