C++ Library - <print>
The <print> header in C++, provides functions for printing formatted output directly to standard output (stdout). This header is part of the Input/Output library.
It provides a range of features for formatted output and easier to use compared to traditional printf.
Including <print> Header
Before using any function of the <print> header, we need to include it by using the following command.
#include <print>
Functions of <print> Header
Below is list of all functions from <print> header.
| S.NO | Functions & Description |
|---|---|
| 1 | print()
This function prints to stdout or a file stream. It accepts a format string followed by arguments. |
| 2 | println()
This function works same as std::print, but it appends a newline character at the end of each output. |
| 3 | vprint_unicode()
This function is used to print formatted output to Unicode-capable stdout or file streams. |
| 4 | vprint_unicode_buffered()
This function works same as vprint_unicode but it enable buffering, which collects output into a buffer. |
| 5 | vprint_nonunicode()
This function is used is used for formatted output to stdout or file streams without Unicode support. |
| 6 | vprint_nonunicode_buffered()
This function works is the buffered version of vprint_nonunicode, which collects output into a buffer. |
Printing with Newline
In the below example we are going to use, println which works like print but adds a newline character at the end of the output.
#include <cstdio>
int main() {
std::printf("Hello, %s!\n", "World");
return 0;
}
Output
If we run the above code it will generate the following output
Hello, World!