0% found this document useful (0 votes)
2 views5 pages

std__basic_ostream - cppreference.com

The document provides an overview of the std::basic_ostream class in C++, which supports high-level output operations for character streams, including formatted and unformatted output. It details the class's inheritance structure, member types, functions, and global objects, as well as various formatting flags and state functions. Additionally, it outlines the member classes and functions inherited from std::basic_ios and std::ios_base.

Uploaded by

ardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

std__basic_ostream - cppreference.com

The document provides an overview of the std::basic_ostream class in C++, which supports high-level output operations for character streams, including formatted and unformatted output. It details the class's inheritance structure, member types, functions, and global objects, as well as various formatting flags and state functions. Additionally, it outlines the member classes and functions inherited from std::basic_ios and std::ios_base.

Uploaded by

ardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

05/09/2024, 11:49 std::basic_ostream - cppreference.

com

std:: basic_ostream
Definido no cabeçalho<ostream>
modelo <
classe CharT,
classe Traits = std:: char_traits < CharT >
> classe basic_ostream : virtual público std:: basic_ios < CharT, Traits >

O modelo de classe basic_ostreamfornece suporte para operações de saída de alto nível em fluxos de caracteres.
As operações suportadas incluem saída formatada (por exemplo, valores inteiros) e saída não formatada (por
exemplo, caracteres brutos e matrizes de caracteres). Essa funcionalidade é implementada em termos da interface
fornecida pela basic_streambufclasse, acessada por meio da basic_iosclasse base. Em implementações típicas,
basic_ostreamnão tem membros de dados não herdados.

basic_ios basic_ostream
ios_base <CharT, Traits> <CharT, Traits>

Diagrama de herança

Vários typedefs para tipos de caracteres comuns são fornecidos:


Definido no cabeçalho<ostream>
Tipo Definição
std::ostream std :: basic_ostream < char >
std::wostream std :: basic_ostream < wchar_t >

Objetos globais

Seis basic_ostreamobjetos globais são fornecidos pela biblioteca padrão:


Definido no cabeçalho<iostream>
corte escreve no fluxo de saída C padrão stdout
wcout (objeto global)

cervo escreve no fluxo de erro C padrão stderr , sem buffer


o que é isso (objeto global)
entupir escreve no fluxo de erro C padrão stderr
entupir (objeto global)

Tipos de membros

Tipo de membro Definição


char_type CharT
traits_type Traits; o programa está malformado se Traits::char_typenão for CharT.
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type

Funções de membro

constrói o objeto
(construtor)
(função membro pública)
destrói o objeto
(destruidor) [virtual]
(função de membro público virtual)
move-assigns de outro basic_ostream
operador= (C++11)
(função de membro protegida)

Saída formatada

insere dados formatados


operador<<
(função de membro pública)

https://en.cppreference.com/w/cpp/io/basic_ostream 1/5
05/09/2024, 11:49 std::basic_ostream - cppreference.com

Saída não formatada

insere um caractere
colocar
(função membro pública)
insere blocos de caracteres
escrever
(função de membro pública)

Posicionamento

retorna o indicador de posição de saída


diga
(função de membro pública)
define o indicador de posição de saída
procurar
(função de membro público)

Variado

sincroniza com o dispositivo de armazenamento subjacente


descarga
(função de membro público)
swaps stream objects, except for the associated buffer
trocar (C++11) (protected member function)

Member classes

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

Non-member functions

inserts character data or insert into rvalue stream


operator<<(std::basic_ostream)
(function template)
outputs formatted representation of the arguments
print(std::ostream) (C++23)
(function template)
outputs formatted representation of the arguments with appended
println(std::ostream) (C++23) '\n'
(function template)
performs Unicode aware output using type-erased argument
vprint_unicode(std::ostream) (C++23) representation
(function)
outputs character data using type-erased argument representation
vprint_nonunicode(std::ostream) (C++23)
(function)

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


good
(public member function of std::basic_ios<CharT,Traits>)
checks if end-of-file has been reached
eof
(public member function of std::basic_ios<CharT,Traits>)
checks if an error has occurred
fail
(public member function of std::basic_ios<CharT,Traits>)
checks if a non-recoverable error has occurred
bad
(public member function of std::basic_ios<CharT,Traits>)

https://en.cppreference.com/w/cpp/io/basic_ostream 2/5
05/09/2024, 11:49 std::basic_ostream - cppreference.com
checks if an error has occurred (synonym of fail())
operator!
(public member function of std::basic_ios<CharT,Traits>)
checks if no error has occurred (synonym of !fail())
operator bool
(public member function of std::basic_ios<CharT,Traits>)
returns state flags
rdstate
(public member function of std::basic_ios<CharT,Traits>)
sets state flags
setstate
(public member function of std::basic_ios<CharT,Traits>)
modifies state flags
clear
(public member function of std::basic_ios<CharT,Traits>)

Formatting

copies formatting information


copyfmt
(public member function of std::basic_ios<CharT,Traits>)
manages the fill character
fill
(public member function of std::basic_ios<CharT,Traits>)

Miscellaneous

manages exception mask


exceptions
(public member function of std::basic_ios<CharT,Traits>)
sets the locale
imbue
(public member function of std::basic_ios<CharT,Traits>)
manages associated stream buffer
rdbuf
(public member function of std::basic_ios<CharT,Traits>)
manages tied stream
tie
(public member function of std::basic_ios<CharT,Traits>)
narrows characters
narrow
(public member function of std::basic_ios<CharT,Traits>)
widens characters
widen
(public member function of std::basic_ios<CharT,Traits>)

Inherited from std::ios_base

Member functions

Formatting

manages format flags


flags
(public member function of std::ios_base)
sets specific format flag
setf
(public member function of std::ios_base)
clears specific format flag
unsetf (public member function of std::ios_base)
manages decimal precision of floating point operations
precision
(public member function of std::ios_base)
manages field width
width
(public member function of std::ios_base)

Locales

sets locale
imbue
(public member function of std::ios_base)
returns current locale
getloc
(public member function of std::ios_base)

Internal extensible array

returns a program-wide unique integer that is safe to use as index to pword() and
xalloc [static] iword()
(public static member function of std::ios_base)
resizes the private storage if necessary and access to the long element at the
iword given index
(public member function of std::ios_base)
resizes the private storage if necessary and access to the void* element at the
pword given index
(public member function of std::ios_base)

https://en.cppreference.com/w/cpp/io/basic_ostream 3/5
05/09/2024, 11:49 std::basic_ostream - cppreference.com

Miscellaneous

registers event callback function


register_callback
(public member function of std::ios_base)
sets whether C++ and C I/O libraries are interoperable
sync_with_stdio [static] (public static member function of std::ios_base)

Member classes

stream exception
failure
(public member class of std::ios_base)
initializes standard stream objects
Init
(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
openmode 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)

fmtflags formatting flags type

The following constants are also defined:

Constant Explanation
dec use decimal base for integer I/O: see std::dec
oct use octal base for integer I/O: see std::oct
hex use hexadecimal base for integer I/O: see std::hex
basefield dec | oct | hex . Useful for masking operations
left adjustment (adds fill characters to the right): see
left
std::left
right adjustment (adds fill characters to the left): see
right
std::right
ajuste interno (adiciona caracteres de preenchimento
internal
ao ponto designado interno): veja std::internal
esquerda | direita | interna . Útil para
ajuste de campo
operações de mascaramento
gerar tipos de ponto flutuante usando notação
científico científica ou notação hexadecimal se combinada com
fixo : veja std::científico
gerar tipos de ponto flutuante usando notação fixa ou
fixo notação hexadecimal se combinada com científico
: veja std::fixed
científico | fixo . Útil para operações de
campo flutuante
mascaramento
inserir e extrair tipo bool em formato alfanumérico:
boolalfa
veja std::boolalpha
gerar um prefixo indicando a base numérica para
base de exposição saída inteira, requerer o indicador de moeda em E/S
monetária: veja std::showbase
gerar um caractere de ponto decimal
ponto de destaque incondicionalmente para saída de número de ponto
flutuante: veja std::showpoint
gerar um caractere + para saída numérica não
showpos
negativa: veja std::showpos

https://en.cppreference.com/w/cpp/io/basic_ostream 4/5
05/09/2024, 11:49 std::basic_ostream - cppreference.com
pule os espaços em branco iniciais antes de certas
pula-pula
operações de entrada: veja std::skipws
limpe a saída após cada operação de saída: veja
unidadebuf
std::unitbuf
substituir certas letras minúsculas por seus
maiúsculas equivalentes maiúsculos em certas operações de
saída: veja std::uppercase

(tipo definido)
estado do tipo de fluxo

As seguintes constantes também são definidas:

Constante Explicação
boa parte sem erro
iostado
pedaço ruim erro de fluxo irrecuperável
operação de entrada/saída falhou (erro de formatação ou
falha pouco
extração)
eofbit a sequência de entrada associada atingiu o fim do arquivo

(tipo definido)
tipo de direção de busca

As seguintes constantes também são definidas:

Constante Explicação
procurardir implorar o começo de um fluxo
fim o fim de um fluxo
Curioso a posição atual do indicador de posição do fluxo

(tipo definido)
especifica o tipo de evento
evento
(enum)
tipo de função de retorno de chamada
evento_retorno_de_chamada
(typedef)

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_ostream&oldid=165184"

https://en.cppreference.com/w/cpp/io/basic_ostream 5/5

You might also like