簡體   English   中英

在使用xcode 4.6.3的命名空間std中沒有名為'minmax_element'的成員

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

以下代碼在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.

使用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