Espacios de nombres
Variantes
Acciones

std::operator<<,>>

De cppreference.com
< cpp‎ | string‎ | basic string

 
 
Strings biblioteca
Terminadas en nulo
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cadenas de bytes
Multibyte cuerdas
Cadenas anchas
Clases
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
std::basic_string
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Elemento acceso
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los iteradores
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Capacidad
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Operaciones
Original:
Operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Buscar
Original:
Search
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Constantes
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Terceros funciones
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
operator<<operator>>
(C++11)(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Clases de ayuda
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Definido en la cabecera <string>
template <class CharT, class Traits, class Allocator>

std::basic_ostream<CharT, Traits>&
    operator<<(std::basic_ostream<CharT, Traits>& os,

               const std::basic_string<CharT, Traits, Allocator>& str);
(1)
template <class CharT, class Traits, class Allocator>

std::basic_istream<CharT, Traits>&
    operator>>(std::basic_istream<CharT, Traits>& is,

               std::basic_string<CharT, Traits, Allocator>& str);
(2)
1)
En primer lugar, construye un objeto std::basic_ostream::sentry, que vacía el empate () 'd corriente si es necesario y comprueba si hay errores. Si el objeto centinela vuelve false, sale inmediatamente .
Original:
First, constructs a std::basic_ostream::sentry object, which flushes the tie()'d stream if necessary and checks for errors. If the sentry object returns false, exits immediately.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Después, si el objeto centinela vuelve true, determina el relleno de formato de salida en la misma manera que la etapa 3 de num_put::put() .
Original:
Afterwards, if the sentry object returns true, determines the output format padding in the same manner as stage 3 of num_put::put().
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Entonces almacena cada carácter de la secuencia resultante (el contenido de str más relleno) para el flujo de salida os como si se aplicase os.rdbuf()->sputn(seq, n), donde n=std::max(os.width(), str.size())
Original:
Then stores each character from the resulting sequence (the contents of str plus padding) to the output stream os as if by calling os.rdbuf()->sputn(seq, n), where n=std::max(os.width(), str.size())
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Finalmente, llama os.width(0) .
Original:
Finally, calls os.width(0).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
En primer lugar, construye un objeto std::basic_istream::sentry, que vacía el empate () 'd corriente si es necesario, extractos y descarta todos los principales espacios en blanco a menos que la bandera ios_base::skipws estaba despejado, y comprueba si hay errores. Si el objeto centinela vuelve false, sale inmediatamente .
Original:
First, constructs a std::basic_istream::sentry object, which flushes the tie()'d stream if necessary, extracts and discards all leading whitespace characters unless the ios_base::skipws flag was cleared, and checks for errors. If the sentry object returns false, exits immediately.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Después, si el objeto devuelve centinela true, borra str con str.erase()
Original:
Afterwards, if the sentry object returns true, clears str with str.erase()
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Luego lee los caracteres de is y añade a ellos str como por str.append(1, c), hasta que una de las condiciones siguientes sea verdadera:
Original:
Then reads characters from is and appends them to str as if by str.append(1, c), until one of the following conditions becomes true:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • N caracteres son leídos, donde N es is.width() si is.width() > 0, de lo contrario es N str.max_size()
    Original:
    N characters are read, where N is is.width() if is.width() > 0, otherwise N is str.max_size()
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • la condición de fin de archivo se produce en la is corriente
    Original:
    the end-of-file condition occurs in the stream is
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • std::isspace(c,is.getloc()) es cierto para el siguiente carácter c en is (este espacio en blanco permanece en el flujo de entrada) .
    Original:
    std::isspace(c,is.getloc()) is true for the next character c in is (this whitespace character remains in the input stream).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Si no hay ningún carácter extrajo std::ios::failbit se encuentra en is, que puede lanzar std::ios_base::failure .
Original:
If no characters are extracted then std::ios::failbit is set on is, which may throw std::ios_base::failure.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Por último, pide os.width(0) y destruye el objeto std::basic_istream::sentry .
Original:
Finally, calls os.width(0) and destroys the std::basic_istream::sentry object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Excepciones

1)
puede arrojar std::ios_base::failure si se produce una excepción durante la salida .
Original:
may throw std::ios_base::failure if an exception is thrown during output.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
puede arrojar std::ios_base::failure si no hay caracteres son extraídos de is (por ejemplo, la secuencia es al final del archivo, o se compone sólo de espacios en blanco), o si se produce una excepción durante la entrada .
Original:
may throw std::ios_base::failure if no characters are extracted from is (e.g the stream is at end of file, or consists of whitespace only), or if an exception is thrown during input.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Parámetros

os -
una corriente de salida de caracteres
Original:
a character output stream
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is -
una corriente de entrada de caracteres
Original:
a character input stream
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
str -
la cadena que se inserta o se extrae
Original:
the string to be inserted or extracted
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Valor de retorno

1) os

2) is

[editar] Ejemplo

#include <iostream>
#include <string>
 
int main()
{
    std::string greeting = "Hello, whirled!"
    std::cout << greeting << '\n';
}

Salida:

Hello, whirled!