C++ It is one of the most popular programming languages, and a foundation that every programmer should know. This was born as an improved version of C, with features such as object orientation, the use of pointers as references and function overloading, among other improvements. In terms of syntax, both languages are very similar. However, there is a function that has always been missed when programming: the simple “printf” of C to display text on the screen.
Let’s look at a basic example of programming in C. For example, to display text on the screen, just call the function printf(“Hello, World!n”); and write inside, between quotes, the text that we want to display. Something a little more advanced would be to add parameters or other variables that we have defined before. But, broadly speaking, that is the first thing we will learn with this language.
In C++, something as basic and essential as this changes radically. Although there are libraries that allow you to use this C function, such as cstdio, if we do not want to depend on them it was necessary to execute a command such as, for example, std::cout << «Hello, World!n»;. Something that, although you get used to it quickly, is still strange.
Now, those responsible for C++ have just released version 23 of the programming language, an important milestone considering that this language is already 29 years old. And the most surprising thing of all is that, finally, a new function has been included in the main “std” library to display text on the screen almost the same as its predecessor, C, did.
This is how the new C++ println works
Just when we thought that C++ was not going to release anything new, it surprises us. The new version 23 of the programming language now has a new function to display text on the screen: println(). This new feature is located in the main input/output library of this language, stdand will allow text to be displayed on the screen in a much more familiar and simple way than until now.
And why hasn’t the same C printf been used? Probably to avoid compatibility problems, both with C itself and with the function of the cstdio library, which we have already talked about. As it is a new function, there will be no incompatibilities or possible conflicts with the current code or with other libraries.
Of course, all functions used to display text to date, including cstdio’s printf, will continue to work as they have until now. Thus, the new version 23 of C++ does not break compatibility with code created with previous versions. Of course, println will not work with previous versions of this language. And this is a problem.
Because developers rarely update their code, or its dependencies, most existing code, and current programs, will not be updated to this new version. And, therefore, the new println will be as if it did not exist. Maybe in another 29 years we will see new code created with a modern version of C++ that already uses the new println. But for now, we would recommend continuing to learn the strange but familiar std::cout.
We can see all the information about the new C++23 “print” function in this link.