| 1 |
#include <iostream> |
| 2 |
#include <sstream> |
| 3 |
|
| 4 |
using namespace std; |
| 5 |
|
| 6 |
int main() |
| 7 |
{ |
| 8 |
ostringstream ostr("hello ", ios::ate); |
| 9 |
|
| 10 |
cout << ostr.str() << '\n'; |
| 11 |
|
| 12 |
ostr.setf(ios::showbase); |
| 13 |
ostr.setf(ios::hex, ios::basefield); |
| 14 |
ostr << 12345; |
| 15 |
|
| 16 |
cout << ostr.str() << '\n'; |
| 17 |
|
| 18 |
ostr << " -- "; |
| 19 |
ostr.unsetf(ios::hex); |
| 20 |
ostr << 12; |
| 21 |
|
| 22 |
cout << ostr.str() << '\n'; |
| 23 |
|
| 24 |
ostr.str("new text"); |
| 25 |
cout << ostr.str() << '\n'; |
| 26 |
|
| 27 |
ostr.seekp(4, ios::beg); |
| 28 |
ostr << "world"; |
| 29 |
cout << ostr.str() << '\n'; |
| 30 |
} |
| 31 |
/* |
| 32 |
Output from this program: |
| 33 |
hello |
| 34 |
hello 0x3039 |
| 35 |
hello 0x3039 -- 12 |
| 36 |
new text |
| 37 |
new world |
| 38 |
*/ |