Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. NAME basic_stringstream - Supports writing and reading objects of class basic_string<charT,traits,Alocator> to/from an array in memory. SYNOPSIS #include <sstream> template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > class basic_stringstream : public basic_iostream<charT, traits> DESCRIPTION The template class basic_stringstream<charT,traits,Allocator> reads and writes to an array in memory. It supports writing and reading objects of class basic_string<charT,traits,Alocator>. It uses a basic_stringbuf object to control the associated storage. It inherits from basic_iostream_and therefore can use all the formatted and unformatted output and input func- tions. INTERFACE template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > class basic_stringstream : public basic_iostream<charT, traits> { public: typedef traits traits_type; typedef charT char_type; typedef typename traits::int_type int_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef basic_stringbuf<charT, traits, Allocator> sb_type; typedef basic_ios<charT, traits> ios_type; typedef basic_string<charT, traits, Allocator> string_type; explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); explicit basic_stringstream(const string_type& str, ios_base::openmode which = ios_base::out | ios_base::in); virtual ~basic_stringstream(); basic_stringbuf<charT,traits,Allocator> *rdbuf() const; string_type str() const; void str(const string_type& str); }; TYPES char_type The type char_type is a synonym for the template parame- ter charT. int_type The type int_type is a synonym of type traits::in_type. ios_type The type ios_type is an instantiation of class basic_ios on type charT. off_type The type off_type is a synonym of type traits::off_type. pos_type The type pos_type is a synonym of type traits::pos_type. sb_type The type sb_type is an instantiation of class basic_stringbuf on type charT. string_type The type string_type is an instantiation of class basic_string on type charT. stringstream The type stringstream is an instantiation of class basic_stringstream on type char: typedef basic_stringstream<char> stringstream; traits_type The type traits_type is a synonym for the template param- eter traits. wstringstream The type wstringstream is an instantiation of class basic_stringstream on type wchar_t: typedef basic_stringstream<wchar_t> wstringstream; CONSTRUCTORS explicit basic_stringstream(ios_base::openmode which = ios_base::in | ios_base::out); Constructs an object of class basic_stringstream, ini- tializing the base class basic_iostream with the associ- ated string buffer. The string buffer is initialized by calling the basic_stringbuf constructor basic_stringbuf<charT,traits,Allocator>(which). explicit basic_stringstream(const string_type& str, ios_base::openmode which = ios_base::in | ios_base::out); Constructs an object of class basic_stringstream, ini- tializing the base class basic_iostream with the associ- ated string buffer. The string buffer is initialized by calling the basic_stringbuf constructor basic_stringbuf<charT,traits,Allocator>(str,which). DESTRUCTORS virtual ~basic_stringstream(); Destroys an object of class basic_stringstream. MEMBER FUNCTIONS basic_stringbuf<charT,traits,Allocator>* rdbuf() const; Returns a pointer to the basic_stringbuf associated with the stream. string_type str() const; Returns a string object of type string_type whose con- tents is a copy of the underlying buffer contents. void str(const string_type& str); Clears the string buffer and copies the string object str into it. If the opening mode is in, initializes the input sequence to point to the first character of the buffer. If the opening mode is out, initializes the output sequence to point to the first character of the buffer. If the opening mode is out | app, initializes the output sequence to point to the last character of the buffer. EXAMPLE // // stdlib/examples/manual/stringstream.cpp // #include<iostream> #include<sstream> void main ( ) { using namespace std; // create a bi-directional wstringstream object wstringstream inout; // output characters inout << L"Das ist die rede von einem man" << endl; inout << L"C'est l'histoire d'un home" << endl; inout << L"This is the story of a man" << endl; wchar_t p[100]; // extract the first line inout.getline(p,100); // output the first line to stdout wcout << endl << L"Deutch :" << endl; wcout << p; // extract the second line inout.getline(p,100); // output the second line to stdout wcout << endl << L"Francais :" << endl; wcout << p; // extract the third line inout.getline(p,100); // output the third line to stdout wcout << endl << L"English :" << endl; wcout << p; // output the all content of the //wstringstream object to stdout wcout << endl << endl << inout.str(); } SEE ALSO char_traits(3C++), ios_base(3C++), basic_ios(3C++), basic_stringbuf(3C++), basic_string(3C++), basic_istringstream(3C++), basic_ostringstream(3c++) Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Section 27.7.3 STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |