There are many ways to do this, C++ provides some primitive but powerfull tools. Parsing from a std::string usually consists of using the find members to get the positions of tokens you are interested in, then using substring to create a new string consisting of nothing but token. substr(pos,len) makes a copy of a string starting at the pos and is of length len (or length pos to end of string) whichever is less.
There are two ways to read from a stream into a std::string either
cin >> str; that skips whitespace, then reads characters into str until it encounters more whitespace expanding str as needed. char* works the same way except it reads charaiters into the the C style string untill it runs out of space, at which point it reads characters into whatever it would be most inconvenent to have characters read into and silently returns, smug in the knowlage that no_chars_per_page has been set to 1 and your next print job is going to waste a lot of paper.
The other way to read into a std::string is getline(cin,str,'}'); This will read all characters into a string, including whitespace, until it encounters the terminating character, in this case it is '}', by default it's newline. It eats the terminator but does not add it to your string.
In your case I think it's easyer just to parse from the stream. The simple but somewhat unsafe version is this:
Code:
void ez_parse(std::vector<int> &v, std::istream &is=std::cin) {
int n;
char c;
is >> c; // get leading character
do {is >> n >> c; v.push_back(n);} while(c==',');
}
This will put int's into a vector from any input that cosists of any character followed by a number followed by either a non-comma or a comma and another number. {1} or {2, 3, -17 } both satisfy this, and thus work as does $3,2h. behavior is undefined for 5,4,,*. In fact on {3,,4} it will consume infinite memory. The more parinoid and safe version looks like.
Code:
bool parse(std::vector<int> &v, std::istream &is=std::cin) {
int n;
char c=0; // c must not == '{'
is >> c; // get leading '{',
// if the stream is bad
// c is unchanged
if(c != '{') return false; // no leading {, or bad
// stream, bail.
do {
is >> n >> c; // read int,char skipping ws
if(is.good()) v.push_back(n);
else return false; // Doh! (vector unchanged)
} while(c==','); // comma implies another int
return c=='}'; // no comma, was it the end?
}
This version works only for input that is actually of the form "{ num [, num] }" if the return value is true then you can trust all the numbers appended to the vector. If the return value is false then the returned values are good, but possibly incomplete. Both take input from standard input by default, but you can read from a file with ifstream or even a string with istringstream if you want to.
Code:
std::vector<int> v;
if(parse(v)) cout << "ok" << endl;
std::istringstream iss("{5, 6, 7}");
parse(v,iss);
cout << '{';
for(int j = 0;j<v.size()-1;++j) cout << v[j] << ", "
cout << v.back() << '}' << endl;
This will result in a vector of int's with whatever you entered followed by 5, 6, and 7. vectors work almost identically to arrays, the ways they are different mostly involve not sucking.
(edit: tab dammage, last try)
(edit: something like [eye] was parsed as begin italics, as good an example of how *not* to parse as this is, it's confusing)