如何在 Visual Studio 中启用 C++17 编译?
我想使用 C++17 功能。
如何在 Microsoft Visual Studio 中将编译从 C++14 切换到 C++17?
或者说它在 VS 的发布版本中不可用?
I want to use C++17 features.
How can I switch compiling from C++14 to C++17 in Microsoft Visual Studio?
Or is it not available in release versions of VS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
现在有一个下拉菜(至少从vs 2017.3.5起),您可以在其中专门选择C ++ 17。可用的选项(在Project≫属性下> c/c ++语言> c ++语言标准)
/std:C ++ 14
/std:C ++ 17
Visual Studio 2022( MSVC C ++ 20和/std:C ++ 20开关-C ++团队博客):
/std:C ++ 20
任何Visual Studio:
/std:C ++最新
There's now a drop down (at least since VS 2017.3.5) where you can specifically select C++17. The available options are (under project > Properties > C/C++ > Language > C++ Language Standard)
/std:c++14
/std:c++17
Visual Studio 2022 (MSVC C++20 and the /std:c++20 Switch - C++ Team Blog):
/std:c++20
Any Visual Studio:
/std:c++latest
MSBuild(Visual Studio 项目/解决方案*.vcproj/*.sln):
添加到项目设置中的其他选项:
/std:c++latest 以启用最新功能 - 目前为 VS2017、VS2015 Update 3 的 C++17。
https://blogs.msdn。 microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/
/permissive-
将禁用非标准 C++ 扩展并将在 VS2017 中实现标准一致性。https://blogs.msdn.microsoft.com/vcblog/ 2016/11/16/permissive-switch/
编辑(2018 年 10 月): 最新的 VS2017 功能记录如下:
https://learn.microsoft.com/en -gb/cpp/build/reference/std-specify-language-standard-version
VS2017 支持:
/std:[c++14|c++17|c++latest]
现在。这些标志可以通过项目的属性页设置:CMake:
Visual Studio 2017 (15.7+) 支持 CMake 项目。
CMake 可以通过多种方式启用现代 C++ 功能。最基本的选项是通过设置目标的属性 在 CMakeLists.txt 中:
对于接口库:
MSBuild (Visual Studio project/solution *.vcproj/*.sln):
Add to Additional options in Project Settings:
/std:c++latest
to enable latest features - currently C++17 as of VS2017, VS2015 Update 3.https://blogs.msdn.microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/
/permissive-
will disable non-standard C++ extensions and will enable standard conformance in VS2017.https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/
EDIT (Oct 2018): The latest VS2017 features are documented here:
https://learn.microsoft.com/en-gb/cpp/build/reference/std-specify-language-standard-version
VS2017 supports:
/std:[c++14|c++17|c++latest]
now. These flags can be set via the project's property pages:CMake:
Visual Studio 2017 (15.7+) supports CMake projects.
CMake makes it possible to enable modern C++ features in various ways. The most basic option is to enable a modern C++ standard by setting a target's property in CMakeLists.txt:
In the case of an interface library:
Visual studio 2019 版本:
下拉菜单已移至:
Visual studio 2019 version:
The drop down menu was moved to:
Visual Studio 2015 Update 3 不支持您正在寻找的 C++17 功能(
emplace_back()
返回引用)。支持 C++11/14/17 功能(现代 C++)
<一href="https://blogs.msdn.microsoft.com/vcblog/2015/06/19/c111417-features-in-vs-2015-rtm/" rel="noreferrer">C++11/14/17 VS 2015 RTM 中的功能
VS 2015 Update 2 的 STL 是 C++17 到目前为止功能完整
Visual Studio 2015 更新 3
VS 2015 Update 3 中的 STL 修复
Visual Studio 2015 Update 3 does not support the C++17 feature you are looking for (
emplace_back()
returning a reference).Support For C++11/14/17 Features (Modern C++)
C++11/14/17 Features In VS 2015 RTM
VS 2015 Update 2’s STL is C++17-so-far Feature Complete
Visual Studio 2015 Update 3
STL Fixes In VS 2015 Update 3
如果将现有的 Visual Studio 2015 解决方案引入 Visual Studio 2017 并且您想使用 c++17 本机编译器构建它,您应该首先将解决方案/项目重新定位到 v141 ,然后下拉列表将按上述方式显示(配置属性 -> ) C/C++ -> 语言 -> 语言标准)
If bringing existing Visual Studio 2015 solution into Visual Studio 2017 and you want to build it with c++17 native compiler, you should first Retarget the solution/projects to v141 , THEN the dropdown will appear as described above ( Configuration Properties -> C/C++ -> Language -> Language Standard)
vs代码2020版本
tasks.json
file,(使用g ++ -9
构建和调试后)add
-std = C ++ 2A
2020功能(C ++ 1Z
2017功能)。添加
-fconcepts
以使用概念
关键字现在编译,您可以使用2020个功能。
VS Code 2020 version
In
tasks.json
file, (after you build and debug with theg++-9
)Add
-std=c++2a
for 2020 features (c++1z
for 2017 features).Add
-fconcepts
to useconcept
keywordnow compile and you can use the 2020 features.