print() Function in C++

The print() function is used to print the formatted string to the output stream. This function is similar to the old C printf() function in the way it shows output but its internal implementation is based on the modern C++ components.

Syntax of print()

print (" {formatted_string}{} .... ", arguments...);

where,

  • formatted_string: The string to be printed.
  • arguments: Lists of arguments that are to be printed

How to print arguments in formatted_string?

Printing formatted string is different from the old printf() function. Here, arguments are denoted by curly brackets {} at the place where it we want the argument to be printed.

Example: Printing Hello World

C++




// C++ program to print hello world using print satement
#include <iostream>
#include <print>
using namespace std;
  
int main()
{
  
    // new function
    print("Hello World");
  
    return 0;
}


Output

Hello World

C++23 Header

C++ has long been a powerful language, known for its versatility and performance. With each new standard release, the language evolves, introducing features that enhance developer productivity and code readability. One of these additions of the C++ 23 standard is the introduction of <print> header to enhance the output capability of language.

Similar Reads

Header File in C++

The header introduces a set of functions aimed at simplifying and enhancing the way developers handle output formatting in C++. These functions allow the use of the Unicode character set putting it on par with other programming languages which supported these features for long time....

1. print() Function in C++

The print() function is used to print the formatted string to the output stream. This function is similar to the old C printf() function in the way it shows output but its internal implementation is based on the modern C++ components....

2. println() Function in C++

...

Conclusion

The println() function is also used to print the formatted string to the standard output stream but this function additionally prints the new line character (‘\n’) at the end of the output....