string str ( ) const;
void str ( const string & s ); |
|
Get/set the associated string object
The first version returns a copy of the string object currently associated with the string stream buffer.
The second syntax copies the content of string s to the string object associated with the string stream buffer.
The function effectivelly calls rdbuf()->str().
Parameters
- s
- String object whose content is to be copied to the string stream buffer.
Return Value
The second version returns a copy of the
string object currently associated with the stream buffer.
Example
// ostringstream::str
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main () {
ostringstream oss;
string mystr;
oss << "Sample string";
mystr=oss.str();
cout << mystr;
return 0;
}
|
Basic template member declaration
( basic_ostringstream<charT,traits,Allocator> )
basic_string<charT,traits,Allocator> str () const;
void str (const basic_string<charT,traits,Allocator> & s );
|
See also