Apache C++ Standard Library Reference Guide

## istrstream

Library: Input/output

    istrstream  basic_istream  basic_ios  ios_base

- Local Index
- Summary
- Synopsis
- Description
- Interface
- Member Types
- Constructors
- Destructors
- Member Functions
- Example
- See Also
- Standards Conformance

### Local Index

#### Members

char_type int_type istrstream() | off_type pos_type rdbuf() | str() traits_type ~istrstream() |

### Summary

Class that reads characters from an array in memory

### Synopsis

    #include <strstream>

    namespace std {
      class istrstream;
    }

### Description

The class istrstream reads characters from an array in memory. It uses a private strstreambuf object to control the associated array object. It inherits from basic_istream and therefore can use all the formatted and unformatted input functions.

> NOTE -- This is a deprecated feature and might not be available in future versions.

### Interface

    namespace std {

      class istrstream : public basic_istream<char> {

        public:

          typedef char                            char_type;
          typedef char_traits<char_type>          traits_type;
          typedef typename traits_type::int_type  int_type;
          typedef typename traits_type::pos_type  pos_type;
          typedef typename traits_type::off_type  off_type;

          explicit istrstream(const char *s);
          istrstream(const char *s, streamsize n);
          explicit istrstream(char *s);
          istrstream(char *s, streamsize n);

          virtual ~istrstream();

          strstreambuf *rdbuf() const;
          char *str();

        };
    }

### Member Types

    char_type

The type `char_type` is a synonym of type `char`.

    int_type

The type `int_type` is a synonym of type `traits_type::in_type`.

    off_type

The type `off_type` is a synonym of type `traits_type::off_type`.

    pos_type

The type `pos_type` is a synonym of type `traits_type::pos_type`.

    traits_type

The type `traits_type` is a synonym of type `char_traits<char>`.

### Constructors

    explicit istrstream(const char* s);
    explicit istrstream(char* s);

Constructs an object of class istrstream, initializing the base class basic_istream with the associated strstreambuf object. The strstreambuf object is initialized by calling `strstreambuf(s,0)`, where `s` designates the first element of an NTBS (null terminated byte string).

    explicit istrstream(const char* s, streamsize n);
    explicit istrstream(char* s, streamsize n);

Constructs an object of class istrstream, initializing the base class basic_istream with the associated strstreambuf object. The strstreambuf object is initialized by calling `strstreambuf(s,n)`, where `s` designates the first element of an array whose length is `n` elements and `n` is greater than zero.

### Destructors

    virtual ~istrstream();

Destroys an object of class `istrstream`.

### Member Functions

    char*
    str();

Calls `rdbuf()->str()`.

    strstreambuf*
    rdbuf() const;

Returns a pointer to the private strstreambuf object associated with the stream.

### Example

    //
    //  istrstream.cpp
    //

    #include <iostream>    // for cout
    #include <strstream>   // for strstream

    int main ()
    {
        // create two constant istrstream objects and initialize their
        // underlying strstreambufs with string literals; the objects
        // do not create copies of the literals but use them directly
        // for efficiency
        std::istrstream a ("Ce n'est pas l'homme qui prend la mer, ");
        std::istrstream b ("c'est la mer qui prend l'homme.");

        // create a dynamic strstream object
        std::strstream out;

        // output the contents of the streams into out
        out << a.rdbuf () << b.str () << '\n';

        // output the contents of out to standard output
        std::cout << out.rdbuf () << '\n';

        // output the contents of the stream objects to standard output
        std::cout << a.str () << '\n' << b.rdbuf () << '\n';

        // the dtors of a and b will not release any storage
        // since the objects did not allocate any

        // the dtor of out will release allocated storage since
        // neither freeze() nor str() was called on the object

        return 0;
    }

    Program Output:

    Ce n'est pas l'homme qui prend la mer, c'est la mer qui prend l'homme.

    Ce n'est pas l'homme qui prend la mer,
    c'est la mer qui prend l'homme.

### See Also

char_traits, ios_base, basic_ios, strstreambuf, ostrstream, strstream

### Standards Conformance

Deprecated. See ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Annex D Compatibility features Section D.7.2