在 Visual Studio 2019 中控制 C++ 标准修订版 [英] Control C++ Standard Revision in visual studio 2019

查看:34
本文介绍了在 Visual Studio 2019 中控制 C++ 标准修订版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的 C++ 项目中使用了 Visual Studio 2019,我想在编译时控制 C++ 版本.我已将其从项目"更改为属性 >C/C++ >语言C++语言标准"

So I am using the visual studio 2019 for my C++ projects, I wanted to control the C++ version when compiling. I have changed it from "project > properties > C/C++ > Language > C++ Language standard > "

它位于 默认(ISO C++14 标准)

我用它来检查版本:

#include<iostream>
using namespace std;

int main() {
    cout << __cplusplus << endl;
}

但是输出是199711

我把C++语言标准改成了ISO C++17 Standard (/std:c++17)

I changed the C++ language standard to ISO C++17 Standard (/std:c++17)

但是 __cplusplus 的输出仍然是 199711

But still the output of __cplusplus is always 199711

有什么想法吗?

推荐答案

根据 Microsoft 文档:

__cplusplus 预处理器宏通常用于报告支持对于特定版本的 C++ 标准.因为现有的很多代码似乎取决于匹配199711L"的这个宏的值,编译器不会改变宏的值,除非你通过使用/Zc:__cplusplus 编译器选项显式选择加入.这/Zc:__cplusplus 选项从 Visual Studio 2017 开始可用15.7 版,默认关闭.在早期版本的 VisualStudio,默认情况下,或者如果指定了/Zc:__cplusplus-,VisualStudio 返回值199711L";对于 __cplusplus 预处理器宏./permissive- 选项不启用/Zc:__cplusplus.

The __cplusplus preprocessor macro is commonly used to report support for a particular version of the C++ standard. Because lots of existing code appears to depend on the value of this macro matching "199711L", the compiler does not change the value of the macro unless you explicitly opt-in by using the /Zc:__cplusplus compiler option. The /Zc:__cplusplus option is available starting in Visual Studio 2017 version 15.7, and is off by default. In earlier versions of Visual Studio, and by default, or if /Zc:__cplusplus- is specified, Visual Studio returns the value "199711L" for the __cplusplus preprocessor macro. The /permissive- option does not enable /Zc:__cplusplus.

因此,您可以将 /Zc:__cplusplus/Zc:__cplusplus- 添加到 Configuration Properties 中的 Additional options ->C/C++ ->命令行.

So, you could add /Zc:__cplusplus or /Zc:__cplusplus- to the Additional options in Configuration Properties -> C/C++ -> Command Line.

这篇关于在 Visual Studio 2019 中控制 C++ 标准修订版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆