#include <iostream>
#include <sstream>
using namespace std;
int main()
{
stringstream ss("Test");
cout << "#1: " << ss.str() << endl;
ss << "another string";
cout << "#2: " << ss.str() << endl;
return 0;
}
Output:
#1: Test
#2: another string
stringstream has eaten the initial string, which was provided as a parameter to the constructor.
OS: Fedora 8
Compiler: g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)
this one is nice:
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
ostringstream ss("Test");
cout << "#1: " << ss.str() << endl;
ss << "--";
cout << "#2: " << ss.str() << endl;
return 0;
}
Output:
#1: Test
#2: --st
No comments:
Post a Comment