.\" ident @(#)basic_istringstream.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH basic_istringstream 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2basic_istringstream\fP, \f2istringstream\fP, \f2wistringstream\fP \ - Supports reading objects of class basic_string from an array in memory. .SH SYNOPSIS .br #include .br template, .RE .RS 8 class Allocator = allocator > .RE .RS 0 class basic_istringstream .br : public basic_istream .SH DESCRIPTION The template class basic_istringstream reads from an array in memory. It supports reading objects of class basic_string. It uses a \f2basic_stringbuf\fP object to control the associated storage. It inherits from basic_istream and therefore can use all the formatted and unformatted input functions. .SH INTERFACE .br template, .RE .RS 8 class Allocator = allocator > .RE .RS 0 class basic_istringstream .br : public basic_istream { .br .br public: .br .RE .RS 1 typedef basic_stringbuf sb_type; .br typedef basic_ios ios_type; .br typedef basic_string .RE .RS 22 string_type; .RE .RS 0 .RE .RS 1 typedef traits traits_type; .br typedef charT char_type; .br typedef typename traits::int_type int_type; .br typedef typename traits::pos_type pos_type; .br typedef typename traits::off_type off_type; .RE .RS 0 .RE .RS 1 explicit basic_istringstream(ios_base::openmode which = .RE .RS 30 ios_base::in); .RE .RS 0 .RE .RS 1 explicit basic_istringstream(const string_type& str, .RE .RS 30 ios_base::openmode which = .br ios_base::in); .RE .RS 0 .RE .RS 1 virtual ~basic_istringstream(); .br basic_stringbuf *rdbuf() const; .br string_type str() const; .br void str(const string_type& str); .RE .RS 0 .br }; .SH TYPES .br char_type .RE .RS 3 The type \f2char_type\fP is a synonym for the template parameter \f2charT\fP. .RE .br int_type .RE .RS 3 The type \f2int_type\fP is a synonym of type \f2traits::in_type\fP. .RE .br ios_type .RE .RS 3 The type \f2ios_type\fP is an instantiation of class \f2basic_ios\fP on type \f2charT\fP. .RE .br istringstream .RE .RS 3 The type \f2istringstream\fP is an instantiation of class \f2basic_istringstream\fP on type \f2char\fP: \f2typedef basic_istringstream istringstream;\fP .RE .br off_type .RE .RS 3 The type \f2off_type\fP is a synonym of type \f2traits::off_type\fP. .RE .br pos_type .RE .RS 3 The type \f2pos_type\fP is a synonym of type \f2traits::pos_type\fP. .RE .br sb_type .RE .RS 3 The type \f2sb_type\fP is an instantiation of class \f2basic_stringbuf\fP on type \f2charT\fP. .RE .br string_type .RE .RS 3 The type\f2 string_type\fP is an instantiation of class \f2basic_string\fP on type \f2charT\fP. .RE .br traits_type .RE .RS 3 The type \f2traits_type\fP is a synonym for the template parameter \f2traits\fP. .RE .br wistringstream .RE .RS 3 The type \f2wistringstream\fP is an instantiation of class \f2basic_istringstream\fP on type \f2wchar_t\fP: \f2typedef basic_istringstream wistringstream;\fP .RE .SH CONSTRUCTORS .br explicit basic_istringstream(ios_base::openmode which = .RE .RS 28 ios_base::in); .RE .RS 3 Constructs an object of class \f2basic_istringstream\fP, initializing the base class \f2basic_istream \fPwith the associated string buffer. The string buffer is initialized by calling the \f2basic_stringbuf\fP constructor \f2basic_stringbuf(which)\fP. .RE .RE .RS 0 explicit basic_istringstream(const string_type& str, .RE .RS 28 ios_base::openmode which = .br ios_base::in); .RE .RS 3 Constructs an object of class \f2basic_istringstream\fP, initializing the base class \f2basic_istream\fP with the associated string buffer. The string buffer is initialized by calling the \f2basic_stringbuf\fP constructor \f2basic_stringbuf(str,which)\fP. .RE .SH DESTRUCTORS .RE .RS 0 virtual ~basic_istringstream(); .RE .RS 3 Destroys an object of class \f2basic_istringstream\fP. .RE .SH MEMBER FUNCTIONS .br basic_stringbuf* .br rdbuf() const; .RE .RS 3 Returns a pointer to the \f2basic_stringbuf\fP associated with the stream. .RE .br string_type .br str() const; .RE .RS 3 Returns a string object of type \f2string_type\fP, which contains a copy of the underlying buffer contents. .RE .br void .br str(const string_type& str); .RE .RS 3 Clears the string buffer and copies the string object \f2str\fP into it. If the opening mode is \f2in\fP, initializes the input sequence to point to the first character of the buffer. If the opening mode is \f2out\fP, initializes the output sequence to point to the first character of the buffer. If the opening mode is\f2 out | app\fP, initializes the output sequence to point to the last character of the buffer. .RE .SH EXAMPLE .br // .br // stdlib/examples/manual/istringstream.cpp .br // .br #include .br #include .br #include .br #include .br .br void main ( ) .br { .RE .RS 1 using namespace std; .RE .RS 0 .RE .RS 1 long l= 20; .br wchar_t *ntbs=L"Il avait l'air heureux"; .br wchar_t c; .br wchar_t buf[50]; .RE .RS 0 .RE .RS 2 // create a read/write string-stream object on wide char .br // and attach it to an wistringstream object .RE .RS 1 wistringstream in(ios_base::in | ios_base::out); .RE .RS 0 .RE .RS 2 // tie the ostream object to the wistringstream object .RE .RS 1 wostream out(in.rdbuf()); .RE .RS 0 .RE .RS 2 // output ntbs in out .RE .RS 1 out << ntbs; .RE .RS 0 .RE .RS 2 // output each word on a separate line .RE .RS 1 while ( in.get(c) ) .RE .RS 3 { .RE .RS 4 if ( c == L' ' ) .RE .RS 5 wcout << endl; .RE .RS 4 else .RE .RS 5 wcout << c; .RE .RS 3 } .RE .RS 1 wcout << endl << endl; .RE .RS 0 .RE .RS 2 // move back the input sequence to the beginning .RE .RS 1 in.seekg(0); .RE .RS 0 .RE .RS 2 // clear the state flags .RE .RS 1 in.clear(); .RE .RS 0 .RE .RS 2 // does the same thing as the previous code .br // output each word on a separate line .RE .RS 1 while ( in >> buf ) .RE .RS 2 wcout << buf << endl; .RE .RS 4 .RE .RS 1 wcout << endl << endl; .RE .RS 0 .RE .RS 2 // create a tiny string object .RE .RS 1 string test_string("Il dormait pour l'eternite"); .RE .RS 0 .RE .RS 2 // create a read/write string-stream object on char .br // and attach it to an istringstream object .RE .RS 1 istringstream in_bis(ios_base:: in | ios_base::out | .RE .RS 22 ios_base::app ); .RE .RS 0 .RE .RS 2 // create an ostream object .RE .RS 1 ostream out_bis(in_bis.rdbuf()); .RE .RS 0 .RE .RS 2 // initialize the string buffer with test_string .RE .RS 1 in_bis.str(test_string); .RE .RS 0 .RE .RS 1 out_bis << endl; .RE .RS 0 .RE .RS 2 // output the base info before each integer .RE .RS 1 out_bis << showbase; .RE .RS 0 .RE .RS 1 ostream::pos_type pos= out_bis.tellp(); .RE .RS 0 .RE .RS 2 // output l in hex with a field with of 20 .RE .RS 1 out_bis << hex << setw(20) << l << endl; .RE .RS 0 .RE .RS 2 // output l in oct with a field with of 20 .RE .RS 1 out_bis << oct << setw(20) << l << endl; .RE .RS 0 .RE .RS 2 // output l in dec with a field with of 20 .RE .RS 1 out_bis << dec << setw(20) << l << endl; .RE .RS 0 .RE .RS 2 // output the all buffer .RE .RS 1 cout << in_bis.rdbuf(); .RE .RS 0 .RE .RS 2 // seek the input sequence to pos .RE .RS 1 in_bis.seekg(pos); .RE .RS 0 .RE .RS 1 int a,b,d; .RE .RS 0 .RE .RS 2 // read the previous outputted integer .RE .RS 1 in_bis >> a >> b >> d; .RE .RS 0 .RE .RS 2 // output 3 times 20 .RE .RS 1 cout << a << endl << b << endl << d << endl; .RE .RS 0 .br } .SH SEE ALSO char_traits(3C++), ios_base(3C++), basic_ios(3C++), basic_stringbuf(3C++), basic_string(3C++), basic_ostringstream(3C++), basic_stringstream(3C++) Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Section 27.7.2 .SH STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee