Ine*_*nce 2 c++ syntax iterator c++11 c++14
在这个问题(/sf/ask/484850341/)中,user703016使用以下语法来访问vector cards_的迭代器:
对于C++ 98,他们建议使用:cards_.begin()和cards_.end()
对于C++ 11,他们建议使用:std :: begin(cards_)和std :: end(cards_)
对于C++ 14,哪种语法更可取,两者之间是否有任何真正的区别?在今天之前,我只看到了第一种语法.
只要你处理一个vector,你使用它没有任何区别.
std::begin()并且std::end()将,但是,在工作,某些情况下.begin(),并.end()不会起作用.主要的是使用内置数组.例如,这将正常工作:
char foo[] = "17395";
std::sort(std::begin(foo), std::end(foo));
Run Code Online (Sandbox Code Playgroud)
当然foo.begin()并且foo.end()不可能工作,因为内置数组没有任何成员函数.