C++11 : 错误:“开始”不是“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标准。
除了在启用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
相关文章:
- std::ofstream 作为类成员删除复制构造函数?
- 使用 std::index_sequence 初始化具有固定大小数组成员的 POD 结构容器
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- 使用 std::async 时死锁,将来作为成员
- 访问 std:vector 的类成员 std:vector 在一个类中与另一个 std:vector
- 将此类的智能指针追加到成员 std::vector
- 在Visual Studio中删除成员std::vector::d ata()
- C++初始化/填充静态成员 std::数组元素到特定值
- 是否可以在同一对象中对成员 std::shared_ptr 进行成员引用<variable>?
- 成员std::future防止boost::shared_ptr超出范围
- 在GCC中使用Brace Initializer初始化成员STD ::数组时错误
- 错误:非静态引用成员"std::ostream&Student::out",无法使用默认赋值运算符
- 获取指向成员std::string::size的指针无法与libc++链接,但可以与libstdc++一起使用
- 如何创建静态常量成员 std::string 数组
- 如何在构造函数初始值设定项列表中初始化“std::unique_ptr”对象的类成员“std::vector”
- C++ 编译失败,并显示错误:命名空间中没有名为 'snprintf' 的成员'std'
- 重载类下标运算符以访问成员std::vector对象的元素
- 构造类成员 std::vector<std::unique_ptr > 的智能方法<AClass>
- 使用成员std::vector移动语义
- 初始化类成员std::函数时编译错误