Hello World? Really?
published at 17.04.2025 21:39 by Jens Weller
Save to Instapaper Pocket
Some one suggested I'd start my new newsletter about learning C++ with my thoughts on hello world in the age of C++23.
Since C++23 one can simplyfy the classic hello world simply to println("Hello World"); Which I think is fairly boring. Using print or println like in the example for print at cppreference is something I find more useful: std::print|ln("{2} {1}{0}!\n", 23, "C++", "Hello"); With this, one sees and understands how to add variables/values to the output, which also the traditional std::cout based HelloWorld achieves.
But there is another option which I haven't heard to much about. C++ has many ways to print to the console, and one of the disadvantages of the above versions is that it depends on the linker. Maybe the compilation time isn't so sad as isn't in play, but if our goal is to teach beginners the important parts of C++, we could do so faster, without even needing the linker.
static_assert(false,"Hello World"); will print also Hello World to the console. This also directly introduces you to an important feature of C++, compile time errors and what they mean. One could even contemplate using std::format to add support for arguments, since in C++26 static_assert is allowed to take a constexpr string. The only piece missing is that also format is constexpr, which is being worked on.
Join the Meeting C++ patreon community!
This and other posts on Meeting C++ are enabled by my supporters on patreon!