[英]Is std::vector::begin() from priorC++11 equivalent to std::vector::data() in C++11?
[英]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.