Linux 我目前使用的是什么 C++ norme?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10026150/
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-06 05:37:26  来源:igfitidea点击:

what c++ norme i'm currently using?

c++linuxcompiler-constructionc++11

提问by Joy

Recently I had faced compiling errors in a c++ code I wrote so I've been asked if I was using a C++11 compiler, but honestly I don't know how to check on my compiler version ! so any idea how to figure this out ??

最近我在编写的 C++ 代码中遇到了编译错误,所以有人问我是否使用 C++11 编译器,但老实说我不知道​​如何检查我的编译器版本!所以知道如何解决这个问题吗?

Btw I'm using codeblocks as an IDE which includes the GCC compiler and GDB debugger from MinGW. also if I'm compiling my c++ code under Linux what command should I run to know my compiler version ?

顺便说一句,我使用代码块作为 IDE,其中包括来自 MinGW 的 GCC 编译器和 GDB 调试器。另外,如果我在 Linux 下编译我的 C++ 代码,我应该运行什么命令来了解我的编译器版本?

采纳答案by James Kanze

That can be a tricky question. C++11 refers to a version of the standard, not to a version of the compiler. Different compilers, and different versions of any given compiler, will typically implement a mix of versions of the standard, at least for recent versions. More or less, because any implementation of C++11 will be fairly new, and thus probably fairly buggy.

这可能是一个棘手的问题。C++11 指的是标准的一个版本,而不是编译器的版本。不同的编译器,以及任何给定编译器的不同版本,通常会实现标准的混合版本,至少对于最近的版本。或多或少,因为 C++11 的任何实现都将是相当新的,因此可能相当有缺陷。

Most compilers have options to output the version; many will output it systematically in verbose mode. For g++, try g++ --version. Recent versions of g++ do have some support for C++11, but you have to activate it with -std=c++0x(rather than the usual -std=c++03or -std=c++98). As the name (c++0x, rather than c++11) indicates, it is nottruly C++11; it is an implementation of some (most?) of the major new features, in a preliminary version based on various working papers, and not the final standard.

大多数编译器都有输出版本的选项;许多人会以详细模式系统地输出它。对于 g++,请尝试g++ --version. 最新版本的 g++ 确实对 C++11 有一些支持,但您必须使用-std=c++0x(而不是通常的-std=c++03-std=c++98)激活它。正如名称 ( c++0x, 而不是c++11) 所示,它并不是真正的 C++11;它是一些(大多数?)主要新功能的实现,是基于各种工作文件的初步版本,而不是最终标准。

(FWIW: I don't think any compiler fully implements all of C++11, but I'd love to be proven wrong.)

(FWIW:我认为没有任何编译器完全实现了 C++11,但我很想被证明是错误的。)

回答by juanchopanza

You can find out your compiler version like this:

你可以像这样找到你的编译器版本:

g++ --version

That doesn't tell you if you are using c++11. To use c++11 features, you would have to call the compiler with thr -std=c++0xflag:

这不会告诉您是否使用 c++11。要使用 c++11 功能,您必须使用 thr-std=c++0x标志调用编译器:

g++ -std=c++0x ....

Bear in mind that gcc doesn't implement 100% of c++11 yet, and how much it implements depends on the version. See herefor a table of supported features.

请记住,gcc 还没有实现 100% 的 c++11,它实现的程度取决于版本。有关支持的功能表,请参见此处

EDIT: strictly speaking, if you are using GCC you cannot be using a fully compliant c++11 compiler due to the missing features. But versions 4.6.1 onwards cover a great deal of the standard.

编辑:严格来说,如果您使用 GCC,则由于缺少功能,您无法使用完全兼容的 c++11 编译器。但是 4.6.1 及以后的版本涵盖了大量标准。

回答by Nathan S.

If you're in linux, checking the version is easy.

如果您使用的是 linux,则检查版本很容易。

> gcc --version

Will tell you the version you have. Note that GCC C++11 support is incomplete still, you can find the details here: http://gcc.gnu.org/projects/cxx0x.html

会告诉你你的版本。请注意,GCC C++11 支持仍然不完整,您可以在此处找到详细信息:http: //gcc.gnu.org/projects/cxx0x.html

I've used a few C++11 features myself, namely initializer lists, and the nullptrconstant. I'm using GCC 4.6 and it's working fine.

我自己使用了一些 C++11 特性,即初始化列表和nullptr常量。我正在使用 GCC 4.6,它工作正常。

edit: And yes, as @jaunchopanza said, you'll need the -std=c++0xcompiler flag to make it work. If you're using Code::Blocks, just right-click on your project, choose Build options..., and check the item that says Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]

编辑:是的,正如@jaunchopanza 所说,您需要-std=c++0x编译器标志才能使其工作。如果您使用的是 Code::Blocks,只需右键单击您的项目,选择Build options...,然后检查显示Have g++ follow thecoming C++0x ISO C++ language standard [-std=c+ +0x]