# std::basic_ostringstream

< cpp‎ | io

C++
 Compiler support Freestanding and hosted Language Standard library Standard library headers Named requirements Feature test macros (C++20) Language support library Concepts library (C++20) Metaprogramming library (C++11) Diagnostics library General utilities library Strings library Containers library Iterators library Ranges library (C++20) Algorithms library Numerics library Localizations library Input/output library Filesystem library (C++17) Regular expressions library (C++11) Concurrency support library (C++11) Technical specifications Symbols index External libraries

Input/output library
 I/O manipulators Print functions (C++23) C-style I/O Buffers basic_streambuf basic_filebuf basic_stringbuf basic_spanbuf(C++23) strstreambuf(deprecated in C++98) basic_syncbuf(C++20) Streams Abstractions ios_base basic_ios basic_istream basic_ostream basic_iostream File I/O basic_ifstream basic_ofstream basic_fstream String I/O basic_istringstream basic_ostringstream basic_stringstream Array I/O basic_ispanstream(C++23) basic_ospanstream(C++23) basic_spanstream(C++23) istrstream(deprecated in C++98) ostrstream(deprecated in C++98) strstream(deprecated in C++98) Synchronized Output basic_osyncstream(C++20) Types streamoff streamsize fpos Error category interface iostream_category(C++11) io_errc(C++11)

std::basic_ostringstream
 Member functions basic_ostringstream::basic_ostringstream basic_ostringstream::operator= basic_ostringstream::swap(C++11) basic_ostringstream::rdbuf String operations basic_ostringstream::str basic_ostringstream::view(C++20) Non-member functions

 Defined in header  template<     class CharT,     class Traits = std::char_traits,     class Allocator = std::allocator > class basic_ostringstream : public basic_ostream;

The class template std::basic_ostringstream implements output operations on string based streams. It effectively stores an instance of std::basic_string and performs output operations to it.

At the low level, the class essentially wraps a raw string device implementation of std::basic_stringbuf into a higher-level interface of std::basic_ostream. The complete interface to unique std::basic_stringbuf members is provided. Inheritance diagram

Two specializations for common character types are also defined:

 Defined in header  Type Definition ostringstream basic_ostringstream wostringstream basic_ostringstream

## Contents

### Member types

 Member type Definition char_type CharT traits_type Traits; the program is ill-formed if Traits::char_type is not CharT. int_type Traits::int_type pos_type Traits::pos_type off_type Traits::off_type allocator_type Allocator

### Member functions

constructs the string stream
(public member function) 
(C++11)
moves the string stream
(public member function) 
(C++11)
swaps two string streams
(public member function) 
returns the underlying raw string device object
(public member function) 
##### String operations
gets or sets the contents of underlying string device object
(public member function) 
(C++20)
obtains a view over the contents of underlying string device object
(public member function) 

### Non-member functions

 specializes the std::swap algorithm (function template) 

## Inherited from std::basic_ostream

### Member functions

##### Formatted output
inserts formatted data
(public member function of std::basic_ostream<CharT,Traits>) 
##### Unformatted output
inserts a character
(public member function of std::basic_ostream<CharT,Traits>) 
inserts blocks of characters
(public member function of std::basic_ostream<CharT,Traits>) 
##### Positioning
returns the output position indicator
(public member function of std::basic_ostream<CharT,Traits>) 
sets the output position indicator
(public member function of std::basic_ostream<CharT,Traits>) 
##### Miscellaneous
synchronizes with the underlying storage device
(public member function of std::basic_ostream<CharT,Traits>) 

### Member classes

 sentry implements basic logic for preparation of the stream for output operations (public member class of std::basic_ostream) 

## Inherited from std::basic_ios

### Member types

 Member type Definition char_type CharT traits_type Traits int_type Traits::int_type pos_type Traits::pos_type off_type Traits::off_type

### Member functions

##### State functions
checks if no error has occurred i.e. I/O operations are available
(public member function of std::basic_ios<CharT,Traits>) 
checks if end-of-file has been reached
(public member function of std::basic_ios<CharT,Traits>) 
checks if an error has occurred
(public member function of std::basic_ios<CharT,Traits>) 
checks if a non-recoverable error has occurred
(public member function of std::basic_ios<CharT,Traits>) 
checks if an error has occurred (synonym of fail())
(public member function of std::basic_ios<CharT,Traits>) 
(until C++11)(since C++11)
checks if no error has occurred (synonym of !fail())
(public member function of std::basic_ios<CharT,Traits>) 
returns state flags
(public member function of std::basic_ios<CharT,Traits>) 
sets state flags
(public member function of std::basic_ios<CharT,Traits>) 
modifies state flags
(public member function of std::basic_ios<CharT,Traits>) 
##### Formatting
copies formatting information
(public member function of std::basic_ios<CharT,Traits>) 
manages the fill character
(public member function of std::basic_ios<CharT,Traits>) 
##### Miscellaneous
(public member function of std::basic_ios<CharT,Traits>) 
sets the locale
(public member function of std::basic_ios<CharT,Traits>) 
manages associated stream buffer
(public member function of std::basic_ios<CharT,Traits>) 
manages tied stream
(public member function of std::basic_ios<CharT,Traits>) 
narrows characters
(public member function of std::basic_ios<CharT,Traits>) 
widens characters
(public member function of std::basic_ios<CharT,Traits>) 

## Inherited from std::ios_base

### Member functions

##### Formatting
manages format flags
(public member function of std::ios_base) 
sets specific format flag
(public member function of std::ios_base) 
clears specific format flag
(public member function of std::ios_base) 
manages decimal precision of floating point operations
(public member function of std::ios_base) 
manages field width
(public member function of std::ios_base) 
##### Locales
sets locale
(public member function of std::ios_base) 
returns current locale
(public member function of std::ios_base) 
##### Internal extensible array
[static]
returns a program-wide unique integer that is safe to use as index to pword() and iword()
(public static member function of std::ios_base) 
resizes the private storage if necessary and access to the long element at the given index
(public member function of std::ios_base) 
resizes the private storage if necessary and access to the void* element at the given index
(public member function of std::ios_base) 
##### Miscellaneous
registers event callback function
(public member function of std::ios_base) 
sets whether C++ and C I/O libraries are interoperable
(public static member function of std::ios_base) 
##### Member classes
stream exception
(public member class of std::ios_base) 
initializes standard stream objects
(public member class of std::ios_base) 

### Member types and constants

Type Explanation
stream open mode type

The following constants are also defined:

 Constant Explanation app seek to the end of stream before each write binary open in binary mode in open for reading out open for writing trunc discard the contents of the stream when opening ate seek to the end of stream immediately after open noreplace (C++23) open in exclusive mode

(typedef) 
formatting flags type

The following constants are also defined:

(typedef) 
state of the stream type

The following constants are also defined:

 Constant Explanation goodbit no error  badbit irrecoverable stream error  failbit input/output operation failed (formatting or extraction error)  eofbit associated input sequence has reached end-of-file 

(typedef) 
seeking direction type

The following constants are also defined:

 Constant Explanation beg the beginning of a stream  end the ending of a stream  cur the current position of stream position indicator 

(typedef) 
specifies event type
(enum) 
callback function type
(typedef)
{"ft_lang_label":"__label__en","ft_lang_prob":0.7478413,"math_prob":0.5593067,"size":6050,"snap":"2022-40-2023-06","text_gpt3_token_len":1427,"char_repetition_ratio":0.2884552,"word_repetition_ratio":0.3144654,"special_character_ratio":0.22264463,"punctuation_ratio":0.15432099,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96880245,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-04T15:51:20Z\",\"WARC-Record-ID\":\"<urn:uuid:16f4b149-eb0b-4180-b879-414ee88f561c>\",\"Content-Length\":\"101841\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:84930571-a61b-437d-88a8-257571fe4395>\",\"WARC-Concurrent-To\":\"<urn:uuid:bb852efe-5eba-47eb-8cdb-f4bc53238e4b>\",\"WARC-IP-Address\":\"74.114.90.46\",\"WARC-Target-URI\":\"https://en.cppreference.com/w/cpp/io/basic_ostringstream\",\"WARC-Payload-Digest\":\"sha1:ZWQM6XIPQHDSYRBZMRERIRZGXKYWSZY6\",\"WARC-Block-Digest\":\"sha1:7FRWD6JA4XRNHR4A3EZ2ALBPSEGI5GMC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500140.36_warc_CC-MAIN-20230204142302-20230204172302-00505.warc.gz\"}"}