B
bml
Could you help and answer my questions of istringstream? Thanks a lot!
1. Reuse an "istringstream"
istringstream ist;
ist.str("This is FIRST test string");
ist.str("This is SECOND test string");
cout << ist.str() << endl;
Is there any problem with the above code?
Is it necessary to add "ist.clear();" between those two "ist.str()"?
2. Sub-string of an "istringstream"
string str1, str2, str3, str4;
ist >> str1 ;
ist >> str2 ;
ist >> str3;
ist >> str4;
How to insert the sub-string, "test", directly into str4, without going
through str1, str2, and str3?
How to remove the counterpart of "str1" from "ist" after "ist >> str1;",
"str1" from "ist" after "ist >> str1;" and so on?
3. Usage of skipws
istringstream ist;
ist.str("This is FIRST test string");
ist >> str1 ;
ist >> str2 ;
ist >> str3;
ist >> str4;
ist >> skipws >> str1 ;
ist >> skipws >> str2 ;
ist >> skipws >> str3;
ist >> skipws >> str4;
Adding "skipws" don't change format and content of str1,...str4 at all? So
what's the usage of "skipws"?
4. Why need ostringstream and istringstream separate, instead of combining
them into a single one with both ">>" and "<<"?
1. Reuse an "istringstream"
istringstream ist;
ist.str("This is FIRST test string");
ist.str("This is SECOND test string");
cout << ist.str() << endl;
Is there any problem with the above code?
Is it necessary to add "ist.clear();" between those two "ist.str()"?
2. Sub-string of an "istringstream"
string str1, str2, str3, str4;
ist >> str1 ;
ist >> str2 ;
ist >> str3;
ist >> str4;
How to insert the sub-string, "test", directly into str4, without going
through str1, str2, and str3?
How to remove the counterpart of "str1" from "ist" after "ist >> str1;",
"str1" from "ist" after "ist >> str1;" and so on?
3. Usage of skipws
istringstream ist;
ist.str("This is FIRST test string");
ist >> str1 ;
ist >> str2 ;
ist >> str3;
ist >> str4;
ist >> skipws >> str1 ;
ist >> skipws >> str2 ;
ist >> skipws >> str3;
ist >> skipws >> str4;
Adding "skipws" don't change format and content of str1,...str4 at all? So
what's the usage of "skipws"?
4. Why need ostringstream and istringstream separate, instead of combining
them into a single one with both ">>" and "<<"?