cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : istringstream : str
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
istringstream
· istringstream::istrings...
member functions:
· istringstream::rdbuf
· istringstream::str

-

istringstream::str public member function
string str ( ) const;
void str ( const string & s );

Get/set the string content

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

// istringstream::str
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main () {

  int val,n;

  istringstream iss;
  string strvalues = "32 240 2 1450";

  iss.str (strvalues);

  for (n=0; n<4; n++)
  {
    iss >> val;
    cout << val+1 << endl;
  }

  return 0;
}

This example uses the str member to copy the content of the string object strvalues to the internal associated string object in the istringstream iss.

Basic template member declaration

( basic_istringstream<charT,traits,Allocator> )
basic_string<charT,traits,Allocator> str () const;
void str (const basic_string<charT,traits,Allocator> & s );

See also

istringstream::istringstream Construct an object and optionally initialize its content (constructor member)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us