MinGW 的 C++11 功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16136142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:05:50  来源:igfitidea点击:

C++11 functionality with MinGW

c++windowsc++11mingw

提问by pdrak

I try to use emplace()function for an unordered_map and compiler says that no such function exists.

我尝试对emplace()unordered_map使用函数,编译器说不存在这样的函数。

I put -std=c+11and it says cc1plus.exe: error: unrecognized command line option '-std=c+11'

我把-std=c+11它说cc1plus.exe: error: unrecognized command line option '-std=c+11'

Can i somehow use C++11 functionality with mingw?

我可以以某种方式在 mingw 中使用 C++11 功能吗?

回答by TemplateRex

From the GCC documentation

来自GCC 文档

C++0x was the working name of a new ISO C++ standard, which was then released in 2011 as C++11 and introduces a host of new features into the standard C++ language and library. This project seeks to implement new C++11 features in GCC and to make it one of the first compilers to bring C++11 to C++ programmers.

C++11 features are available as part of the "mainline" GCC compiler in the trunk of GCC's Subversion repository and in GCC 4.3 and later. To enable C++0x support, add the command-line parameter -std=c++0xto your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x to your g++ command line. GCC 4.7 and later support -std=c++11and -std=gnu++11 as well.

C++0x 是新 ISO C++ 标准的工作名称,该标准于 2011 年以 C++11 的形式发布,并在标准 C++ 语言和库中引入了许多新功能。该项目旨在在 GCC 中实现新的 C++11 特性,并使其成为首批将 C++11 带给 C++ 程序员的编译器之一。

C++11 特性作为“主线”GCC 编译器的一部分在 GCC 的 Subversion 存储库和 GCC 4.3 及更高版本中可用。要启用 C++0x 支持,请将命令行参数-std=c++0x 添加到 g++ 命令行。或者,要启用除 C++0x 扩展之外的 GNU 扩展,请将 -std=gnu++0x 添加到您的 g++ 命令行。GCC 4.7 及更高版本也支持-std=c++11和 -std=gnu++11。

So, for gcc 4.3 through 4.6 use -std=c++0x, for later version use -std=c++11. Library support for map::emplacewas added in gcc 4.8

因此,对于 gcc 4.3 到 4.6 使用 -std=c++0x,对于更高版本使用 -std=c++11。map::emplace在 gcc 4.8 中添加了库支持