Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
cout << endl vs cout << \\\\\"\\n\\\\\" in C++
In C++, both count << endl and count << "\n" are used to insert a new line in the output. But they have an important difference:
COUT << ENDL;
Following are the important point of count << endl;
- Inserts a newline character (\n) and flushes the output buffer.
- Flushing means it forces all output to be written immediately.
- Slower than "\n" in performance-critical situations due to flushing.
- Useful when you want to make sure output appears immediately (e.g., debugging, console logs).
Let's see syntax of the count << endl ?
cout << "tutorialspoint" << endl;
COUT << "\n";
Following are the important point of count << "\n";
- Inserts only a newline character, without flushing the output buffer.
- Faster and preferred when flushing is unnecessary.
- More suitable in performance-sensitive code like competitive programming.
Let's see syntax of the count << "\n" ?
cout << "tutorialspoint \n";
Which One Should be Used?
Use "\n" for better performance in competitive programming. Otherwise, use endl to flush the output and help with debugging.
Advertisements
