简体   繁体   English

在使用xcode 4.6.3的命名空间std中没有名为'minmax_element'的成员

[英]No member named 'minmax_element'in namespace std with xcode 4.6.3

The following codes can compile very well in VC 2010, but when I compile them with xcode 4.6.3 in mac, I have compilation errors as the question title indicates. 以下代码在VC 2010中可以很好地编译,但是当我在Mac中使用xcode 4.6.3编译它们时,如问题标题所示,我遇到了编译错误。 Any ideas? 有任何想法吗? Thanks. 谢谢。

         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);

Use -stdlib=libc++ instead of -stdlib=libstdc++ : 使用-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.

使用cmake,可以通过以下代码轻松实现设置:

 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x  -stdlib=libc++") 

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

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