c++ - xcode 4.6.3 命名空间 std 中没有名为 'minmax_element' 的成员

标签 c++ xcode stl

下面的代码在VC 2010中可以编译的很好,但是在mac中用xcode 4.6.3编译时,出现如题所示的编译错误。有任何想法吗?谢谢。

         std::vector<int> x_array;
    std::vector<int> y_array;

    int min_x,min_y,max_x,max_y;
    auto temp = std::minmax_element(x_array.begin(),x_array.end());
    min_x = *(temp.first);
    max_x = *(temp.second);

最佳答案

使用-stdlib=libc++代替-stdlib=libstdc++:

$ cat test.cpp
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    std::vector<int> x_array;
    std::vector<int> y_array;

    int min_x,min_y,max_x,max_y;
    auto temp = std::minmax_element(x_array.begin(),x_array.end());
    min_x = *(temp.first);
    max_x = *(temp.second);
    return 0;
}

$ clang++ -std=c++0x -stdlib=libc++ -o test test.cpp
$ clang++ -std=c++0x -stdlib=libstdc++ -o test test.cpp
test.cpp:10:22: error: no member named 'minmax_element' in namespace 'std'
    auto temp = std::minmax_element(x_array.begin(),x_array.end());
                ~~~~~^
1 error generated.

关于c++ - xcode 4.6.3 命名空间 std 中没有名为 'minmax_element' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19491489/

相关文章:

c++ - 了解 std::swap()。 tr1::_Remove_reference 的目的是什么?

c++ - 访问存储在 unordered_map 值中的 unordered_map

c++ - std::list 的 const_iterator 与迭代器

c++ - 在将 void* 转换为任何内容时,我应该使用 static_cast 还是 reinterpret_cast

iphone - 无法从另一个 View 的 NSMutable 数组填充 UITableView

ios - 架构 i386 的 undefined symbol : "_OBJC_CLASS_$_Barcode", 引用自:objc-class-ref in

iOS - 确保在主线程上执行

c++ - 在以下情况下,集合插入如何工作?

c++ - 在 Qt 中为形状设置适当的颜色

c++ - Shader编译失败后能否调用glShaderSource更新Shader源码?