C++11标准在2011年8月份获得一致通过,这是自1998年后C++语言第一次大修订,对C++语言进行了改进和扩充。随后各编译器厂商都各自实现或部分实现了C++中的特性。
验证查看编译工具版本:gcc -v;或者g++ -v
验证是否能够正常工作,以新加入到C++11中的std::array为例。
vim stdarray.cpp;
输入C++代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>
#include <array>
int
main()
{
// construction uses aggregate initialization
std::array<
int
, 3> a1{ {1,2,3} };
// double-braces required
std::array<
int
, 3> a2 = {1, 2, 3};
// except after =
std::array<std::string, 2> a3 = { {std::string(
"a"
),
"b"
} };
// container operations are supported
std::sort(a1.begin(), a1.end());
std::reverse_copy(a2.begin(), a2.end(),
std::ostream_iterator<
int
>(std::cout,
" "
));
std::cout <<
'n'
;
// ranged for loop is supported
for
(
auto
& s: a3)
std::cout << s <<
' '
;
std::cout <<
'n'
;
}
|
编译:g++ -std=c++11 -o stdarray stdarray.cpp; ************一定要加上c++11,否则可能无法编译或者无法运行。
运行:./stdarray;
结果输出:
则表示升级后的GCC确实能够支持C++11开发。