In article <11*********************@f14g2000cwb.googlegroups. com>,
"Diane" <fr*********@hotmail.com> wrote:
Could you please explain me how can I output nested strings?
Here is an example:
"adsd{rf[dfF]km}xcv"
The output should start from the inner parentheses, such as:
dfF
rfkm
adsdxcv
Paste the code below in your program (replace what you have) and play
with the code in the "parse_string" function until it works. Instead of
sending output to "cout" send it to "os".
void parse_string( const string& s, ostream& os ) {
// change the code in this method
os << s;
}
int main() {
string test( "hello" );
stringstream ss;
parse_string( test, ss );
assert( ss.str() == test );
test = "Good[hello]by";
ss.str( "" );
parse_string( test, ss );
assert( ss.str() == "hello\nGoodby" );
test = "Good(hello)by";
ss.str( "" );
parse_string( test, ss );
assert( ss.str() == "hello\nGoodby" );
cout << "working\n";
}
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.