std::endl
Aus 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. |
definiert in Header <ostream>
|
||
template< class CharT, class Traits > std::basic_ostream<charT,traits>& endl( std::basic_ostream<CharT, Traits>& os ); |
||
Fügt eine endline Zeichen in der Ausgangsfolge
os
und spült es, als ob durch den Aufruf os.put(os.widen('\n')) durch os.flush() gefolgt . Original:
Inserts a endline character into the output sequence
os
and flushes it as if by calling os.put(os.widen('\n')) followed by 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.
Dies ist ein Nur-Ausgabe-I / O-Manipulators, kann es mit einem Expressionsvektor wie out << std::endl für jede
out
vom Typ std::basic_ostream aufgerufen werden .Original:
This is an output-only I/O manipulator, it may be called with an expression such as out << std::endl 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.
Inhaltsverzeichnis |
[Bearbeiten] Notes
Dieser Manipulator verwendet werden, um eine Linie von Ausgang sofort werden, zB bei der Anzeige Ausgang eines lang andauernden Prozesses, Logging-Aktivität von mehreren Threads oder Protokollierung Aktivität eines Programms, das unerwartet abstürzen kann. Eine explizite Flush von std::cout ist auch vor einem Aufruf von std::system erforderlich, wenn die erzeugten Prozess führt alle Bildschirm-I / O (Ein gängiges Beispiel ist std::system("pause") unter Windows). In den meisten anderen üblichen interaktiven I / O Szenarien ist std::endl überflüssig, wenn mit std::cout verwendet, da jeder Eingang von std::cin, Ausgabe auf std::cerr oder Beendigung des Programms zwingt einen Anruf an std::cout.flush(). Verwendung std::endl statt '\n', von einigen Quellen gefördert werden, erheblich verschlechtern Ausgangsleistung .
Original:
This manipulator may be used to produce a 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(). Use of std::endl in place of '\n', encouraged by some sources, may significantly degrade output performance.
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.
In vielen Implementierungen ist die Standardausgabe line-gepuffert und schriftlich '\n' verursacht einen Flush sowieso, es sei denn, std::cout.sync_with_stdio(false) ausgeführt wurde. In solchen Situationen unnötige
endl
nur verschlechtert die Leistung der Datei-Ausgabe, nicht Standard-Ausgabe .Original:
In many implementations, standard output is line-buffered, and writing '\n' causes a flush anyway, unless std::cout.sync_with_stdio(false) was executed. In those situations, unnecessary
endl
only degrades the performance of file output, not standard output.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.
Die Codebeispiele in diesem Wiki follow Bjarne Stroustrup in Spülen der Standard-Ausgabe nur wo nötig .
Original:
The code samples on this wiki follow Bjarne Stroustrup in flushing the standard output only where necessary.
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.
Wenn eine unvollständige Zeile der Ausgabe gespült werden muss, kann die std::flush Manipulators verwendet werden .
Original:
When an incomplete line of output needs to be flushed, the std::flush 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.
Wenn jedes Zeichen des Ausgangs gespült werden muss, kann die std::unitbuf Manipulators verwendet werden .
Original:
When every character of output 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.
[Bearbeiten] Parameter
os | - | Verweis auf Ausgabe-Stream
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. |
[Bearbeiten] Rückgabewert
os
(Verweis auf den Stream nach 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.
[Bearbeiten] Beispiel
Mit \ n statt endl, würde die Ausgabe identisch sein, kann aber nicht in Echtzeit angezeigt .
Original:
With \n instead of endl, 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 passed" << std::endl; } int main() { std::cout.sync_with_stdio(false); // on some platforms, stdout flushes on \n 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); } }
Output:
487 ms passed 974 ms passed 1470 ms passed 1965 ms passed 2455 ms passed
[Bearbeiten] Siehe auch
Kontrollen, ob die Ausgabe nach jeder Operation wird gespült 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. (Funktion) | |
spült die Ausgabe-Stream Original: 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. (Funktions-Template) | |
synchronisiert mit dem zugrunde liegenden Speicher 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. (öffentliche Elementfunktion of std::basic_ostream )
|