繁体   English   中英

C ++ 11:错误:'begin'不是'std'的成员

[英]C++11 : error: ‘begin’ is not a member of ‘std’

我正在尝试执行以下操作:

source = new int[10];
dest =  new int[10];
std::copy( std::begin(source), std::end(source), std::begin(dest));

但是,编译器报告以下错误。

copy.cpp:5434:14: error: ‘begin’ is not a member of ‘std’
copy.cpp:5434:44: error: ‘end’ is not a member of ‘std’
copy.cpp:5434:72: error: ‘begin’ is not a member of ‘std’

我在代码中包含了必需的<iterator>标头。 有人可以帮我这个吗?

模板函数std :: begin()和std :: end()没有为指针实现(指针不包含有关它们引用的元素数量的信息)而是你应该写的

std::copy( source, source + 10, dest);

至于错误,你应该检查是否包含标题

#include <iterator>

也许你的编译器不支持C ++ 2011 Standard。

除了在启用C ++ 11的编译器中包含<iterator>之外。 你应该知道begin/end对指针没用,它们对数组很有用:

int source[10];
int dest[10];

std::copy(std::begin(source), std::end(source), std::begin(dest));

在linux中使用g ++编译器这个代码也有这个问题。

使用包含C ++特征的g ++编译器应该添加C ++ 11标志

g++ -std=c++11 -o test test.cpp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM