C++20 with Visual Studio

We are in May 2021 and my version of Visual Studio Communitiy is 16.9.5

Launch Visual Studio Installer

Make sure C++ Modules for v142 build tools are also installed

Launch Visual Studio and create an empty project

Add a main.cpp file to the project and paste the following lines into the the source code

import std.core;

int main() {
	std::cout << "Grettings Professor Falken" << '\n';
}

Note that there are no include file. For information, here are the main modules to include:

  • std.core module provides most of the content of the C++ Standard Library
  • std.regex: the content of header 
  • std.filesystem: the content of header 
  • std.memory: the content of header 
  • std.threading: the contents of headers ,

Highlight the project name in Solution Explorer and hit ALT+ENTER to access its properties. Make sure /MD and /EHsc are selected. To do so, select the C/C++ category then the Code generation option. Make sure properties are set for all platforms. If the Runtime library says something like “multiple option” select Debug or Release in the Configuration list box. In Debug mode you should select /MDd and /MD otherwise.

In the Language subcategory make sure that “Preview…” is selected in the “C++ Norm” option and that the “Experimental Modules” are activated (see below). In the next picture, note that the Configuration and Platform options are set to “all configurations” and “all platforms”.

At this point we should be good to go. One last thing… Just to make sure our directory doesn’t become a mess… Again, make sure Configuration and Platform options are set respectively to “all configurations” and “all platforms”. Then in the General group of properties, update the Output directory and Intermediate directory as below:

Output Directory        : $(SolutionDir)build\$(Platform)$(Configuration)\
Intermediate directory  : $(SolutionDir)build\intermediate\$(Platform)$(Configuration)\

Click Apply then OK. When you’re back in the IDE, select Debug and x64.

Hit F5. Welcome in a brand-new world!

Hopefully, the solution directory should not be too messy. Below the build directory contains all the files and directories generated during the builds.

At this point I would recommend saving this project as a template. This will speed up the start of your next C++20 project. To do so, select the Project menu then the “Export Template…” option. Then, follow the instructions and fill the dialog boxes. You can even add your own icon.

Later, a ready to use project will be available. See below the Cpp20 template for example.


Back to top

Published on: May 18 2021 at 11:02 AM | Last updated: Jan 12 2023 at 12:12 AM

Copyright © 1964-2025 - 40tude