C++ 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:
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;