Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;开始()和结束()_C++_Gcc_G++ - Fatal编程技术网

C++ C++;开始()和结束()

C++ C++;开始()和结束(),c++,gcc,g++,C++,Gcc,G++,我正在读《C++入门》第五版。作者不时使用函数begin和end 例如: int ia[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11}; int (*p)[4] = begin(ia); 但是,我得到了一个错误: error: ‘begin’ was not declared in this scope 我正在运行gcc 4.9.2,并使用以下命令进行编译: g++ -std=c++11 main.cpp 作者可能有一个类似的声明,使用名称空间std或使用std:

我正在读《C++入门》第五版。作者不时使用函数
begin
end

例如:

int ia[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};

int (*p)[4] = begin(ia);
但是,我得到了一个错误:

error: ‘begin’ was not declared in this scope
我正在运行gcc 4.9.2,并使用以下命令进行编译:

g++ -std=c++11 main.cpp

作者可能有一个类似
的声明,使用名称空间std
使用std::begin。您需要键入
std::begin
,而不必输入其中一项。您可能还需要
#包括

您需要将其包装在
std
范围内,函数为

很可能在文本中,作者在代码顶部有一个
using
指令

using namespace std;

我不想使用后一种方法。

您必须在声明函数
begin
的地方包含标题

#include <iterator>
然后您必须为
begin

int ( *p )[4] = std::begin( ia );

事实陈述

int ( *p )[4] = std::begin( ia );
相当于

int ( *p )[4] = ia;
表达式
std::end(ia)
相当于
ia+3

auto p = std::begin( ia );
int ( *p )[4] = std::begin( ia );
int ( *p )[4] = ia;