public member function

std::stringbuf::str

<sstream>
  void str ( const string & s );
string str ( ) const;
Get/set the string content
The first version sets a copy of parameter s as the new internal character sequence and intializes the input and output sequences according to the mode used when the object was created.

The second version returns a string object with a copy of the content in the internal character sequence.

Parameters

s
Standard string object whose content is to be copied into the internal character sequence.

Return Value

The second syntax returns a string object with a copy of the content in the internal character sequence.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// stringbuf::str
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main () {

  stringbuf sb;
  string mystr;

  sb.sputn ("Sample string",13);
  mystr=sb.str();

  cout << mystr;

  return 0;
}


Basic template member declaration

( basic_stringbuf<charT,traits,Allocator> )
1
2
basic_string<charT,traits,Allocator> str () const;
void str (const basic_string<charT,traits,Allocator> & s );


See also