Visual Studio 2019 doesn't support C++20 features (yet?). C++20 isn't standard yet, so at best you'd have experimental features, but I don't see modules supported.
MSVC 2019 does support modules, but I'm not sure if it's the exact syntax Peter87 used above. You have to pass /experimental:module to the compiler to enable them. Needless to say, experimental features are just meant to play around with, not for production code.
// need to enable C+ Modules (experimental) and use C++17 or latest language standard
// example copied from
// https://blogs.msdn.microsoft.com/vcblog/2017/05/05/cpp-modules-in-visual-studio-2017/
#pragma warning(disable : 5050) // to disable uncaught_exception warning
import std.core;
#pragma warning(disable : 4996) // to disable uncaught_exception warning
int main()
{
std::vector<std::string> v { "Plato", "Descartes", "Bacon" };
std::copy(v.crbegin(), v.crend(), std::ostream_iterator<std::string>(std::cout, "\n"));
}
Modules support has to be manually switched on. In your project's property settings:
Configuration Settings -> C/C++ -> Language.
Change two switches:
1. C++ Language Standards - either std:c++17 or std:c++latest
2. Enable C++ Modules (experimental) - Yes
As others have said, use it at your own risk. Experimental means experimental. The standard hasn't been set yet.
Get used to typing the std:: qualifier, no matter what. It will make easily preventable headaches less likely to occur in the future.
system() is part of the C library, not C++. Modules don't pull in any of the C library at this experimental stage. Get away from all these "I'm still learning" tricks that are now coming back to bite you.
Check your project's settings. I suspect they are not set properly.
In your project's property settings:
Configuration Settings -> C/C++ -> Language.
Change two switches:
1. C++ Language Standards - either std:c++17 or std:c++latest
2. Enable C++ Modules (experimental) - Yes
I've played around with import/modules since discovering the experimental support was available in VS 2017. And learned the hard way about the project switch settings. They have to be manually set with every new project. And best to check after making changes.
I'll be honest.....until the standard is set in C++20 for using modules the usage is minimal beyond playing around. IMO.
BTW, on further testing with system("pause"); I discovered a typo. It does work with modules pulling in the core std libraries, when fixed.
I personally am very allergic to using it. The function's system commands are not portable.
I'm very big on writing portable code. The effects of invoking a command depend on the system and library implementation, and may cause a program to behave in a non-standard manner or to terminate.
What works with Windows isn't likely to work with Linux/*nix or Mac.
1- Severity Code Description Project File Line Suppression State Error (active) E2914 could not find module file "std.core" for import
2- Severity Code Description Project File Line Suppression State Error C1011 cannot locate standard module interface. Did you install the library part of the C++ modules feature in VS setup?
PS: I'm not sure if I've installed the library part of the C++ modules feature in VS setup! How to check it?
You can check and install the feature using Visual Studio Installler, as the error code suggests (VS setup).
Under Individual Components -> Compilers, build tools, and runtimes -> C++ Modules for v142 build tools (x64/x86 – experimental)
BTW, your picture of the project's language settings obscured the one setting that really needs to be seen: Enable C++ Modules (experimental). It is useless.