The following will do the trick:
string some; int n;
string s = "(someString1 45)(someString2 2432)(anotherString 55)";
stringstream sst(s); // to parse the string
while (sst.get() == '(' && sst >> some >> n && sst.get()==')') {
cout << some << "," << n << endl;
}
This loop will not try to read some string and n
if the open brace is not present.
A slight change could even allow to safely parse further input string if you'd expect something to follow the list of entries between braces:
string s = "(someString1 45)(someString2 2432)(anotherString 55)thats the rest";
...
while (sst.get() == '(') { // open brace to process
if (sst >> some >> n && sst.get() == ')')
cout << some << "," << n << endl; // succesful parse of elements
else {
cout << "Wrong format !!\n"; // something failed
if (!sst.fail()) sst.setf(ios::failbit); // case of missing closing brace
}
}
if (sst) { // if nothing failed, we are here because open brace was missing and there is still input
sst.unget(); // ready to parse the rest, including the char that was checked to be a brace
string rest;
getline(sst, rest);
cout << "The braces are followed by: " << rest << endl;
}