Hacker News new | ask | show | jobs
by Sin2x 1322 days ago
You need to include iostream

https://en.wikipedia.org/wiki/Input/output_(C%2B%2B)#Input/o...

2 comments

The point is the code they cited is relying on a C++ 23 feature (standard modules) which isn't yet ratified (hence the name C++ 23) and nobody yet completely implements.

If you had standard modules, then the import line at the top of that code does get you all of std, including std::cout and thus the I/O streams.

This example is still silly if you do have C++ 23 though because I/O streams are (say it quietly) basically obsolete in C++ 23 since it has a proper imperative print format feature like any modern language - with decent performance and all the format behaviour you're used to from other modern languages.

I expect that, when C++ 23 becomes a thing lots of people actually use, the canonical "Hello, world" example for it will use std::println()

No, this is about modules. See first line and this is verbatim from the book.
You're right. Apparently, it's supported only by MSVC at the moment (Standard Library Modules): https://en.cppreference.com/w/cpp/compiler_support

https://github.com/microsoft/STL/pull/3108

Yep, that's my pull request. :-) At the moment, it's usable if you build the microsoft/STL repo with VS 2022 17.4 Preview 3 or later. When VS 2022 17.5 Preview 1 ships (in the very near future; can't say when exactly), it will be "in box" without the need to build our GitHub repo.

It will still be necessary to build the std.ixx source file (to produce std.ifc and std.obj for consumption; we will never ship prebuilt IFCs/OBJs for the standard modules). It takes maybe 3-5 seconds and doesn't need to be rebuilt until you change your compiler options or upgrade your toolset. Build system support for doing this automatically is a work in progress.

Although we have test coverage running that exercises every header of the Standard Library through `import std;`, we're still working on fixing various compiler bugs, especially in complicated scenarios (e.g. using Ranges through modules). My hope is that the experience will be solid by the time that VS 2022 17.5 is released for production.

Other compilers support modules in varying ways as well, but there's no universal module "std" yet.

Clang also requires some more command line flags to build modules it seems and g++ needs a command line flag to enable module support as well.

Microsoft's compiler seems to have the best language support in many areas, but seems to fail in others (notably the "core language features"). Then again, the standard isn't finished yet.

If I were to write a program in modern C++ I'd go for the Microsoft compiler. The open source and free implementations are clearly not capable of keeping up with a commercial software powerhouse when it comes to a complicated language like C++.