std::flush
De cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Déclaré dans l'en-tête <ostream>
|
||
template< class CharT, class Traits > std::basic_ostream<charT,traits>& flush( std::basic_ostream<CharT, Traits>& os ); |
||
Vide la séquence de sortie
os
comme si en appelant os.flush() . Original:
Flushes the output sequence
os
as if by calling os.flush(). The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Il s'agit d'un manipulateur de sortie uniquement d'E / S, il peut être appelé avec une expression telle que pour tout out << std::flush
out
de std::basic_ostream type .Original:
This is an output-only I/O manipulator, it may be called with an expression such as out << std::flush for any
out
of type std::basic_ostream.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Sommaire |
[modifier] Notes
Ce manipulateur peut être utilisé pour produire une ligne incomplète de sortie immédiatement, par exemple lors de l'affichage de sortie d'un processus de longue durée, l'activité forestière de plusieurs threads ou journalisation de l'activité d'un programme qui peut se bloquer de façon inattendue. Un rinçage explicite de std::cout est également nécessaire avant un appel à std::system, si le processus a engendré exécute n'importe quel écran I / O (un exemple courant est std::system("pause") sous Windows). Dans la plupart des autres habituels entrée / sortie interactive scénarios, std::endl est redondante lorsqu'il est utilisé avec std::cout car toute entrée de std::cin, sortie à std::cerr, ou la fin du programme oblige un appel à std::cout.flush() .
Original:
This manipulator may be used to produce an incomplete line of output immediately, e.g. when displaying output from a long-running process, logging activity of multiple threads or logging activity of a program that may crash unexpectedly. An explicit flush of std::cout is also necessary before a call to std::system, if the spawned process performs any screen I/O (a common example is std::system("pause") on Windows). In most other usual interactive I/O scenarios, std::endl is redundant when used with std::cout because any input from std::cin, output to std::cerr, or program termination forces a call to std::cout.flush().
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Quand une ligne complète de production doit être rincé, le manipulateur std::endl peut être utilisé .
Original:
When a complete line of output needs to be flushed, the std::endl manipulator may be used.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Lorsque chaque opération de sortie doit être balayé, le manipulateur peut être utilisé std::unitbuf .
Original:
When every output operation needs to be flushed, the std::unitbuf manipulator may be used.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Paramètres
os | - | référence aux flux de sortie
Original: reference to output stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifier] Retourne la valeur
os
(référence au flux après la manipulation)Original:
os
(reference to the stream after manipulation)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Exemple
Sans std :: flush, la sortie serait le même, mais peut ne pas apparaître en temps réel .
Original:
Without std::flush, the output would be the same, but may not appear in real time.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> #include <chrono> template<typename Diff> void log_progress(Diff d) { std::cout << "..(" << std::chrono::duration_cast<std::chrono::milliseconds>(d).count() << " ms).." << std::flush; } int main() { volatile int sink=0; auto t1 = std::chrono::high_resolution_clock::now(); for(int j=0; j<5; ++j) { for(int n=0; n<10000; ++n) for(int m=0; m<20000; ++m) sink += m*n; // do some work auto now = std::chrono::high_resolution_clock::now(); log_progress(now - t1); } std::cout << '\n'; }
Résultat :
..(450 ms)....(901 ms)....(1350 ms)....(1800 ms)....(2250 ms)..
[modifier] Voir aussi
contrôle si la sortie est vidé après chaque opération Original: controls whether output is flushed after each operation The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction) | |
sorties '\n' et vide le flux de sortie Original: outputs '\n' and flushes the output stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction générique) | |
synchronise avec le dispositif de stockage sous-jacent Original: synchronizes with the underlying storage device The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::basic_ostream )
|