C++ 没有名为'的成员;最小最大值单元';在命名空间std中使用xcode 4.6.3
下面的代码在VC 2010中可以编译得很好,但是当我在mac中使用xcode 4.6.3编译它们时,正如问题标题所示,我有编译错误。有什么想法吗?谢谢C++ 没有名为'的成员;最小最大值单元';在命名空间std中使用xcode 4.6.3,c++,xcode,stl,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
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);
std::向量x_数组;
std::向量y_数组;
int min_x,min_y,max_x,max_y;
auto temp=std::minmax_元素(x_array.begin(),x_array.end());
最小值x=*(温度优先);
最大值x=*(温度秒);
使用-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.
$cat test.cpp
#包括
#包括
#包括
int main(){
std::向量x_数组;
std::向量y_数组;
int min_x,min_y,max_x,max_y;
auto temp=std::minmax_元素(x_array.begin(),x_array.end());
最小值x=*(温度优先);
最大值x=*(温度秒);
返回0;
}
$clang++-std=c++0x-stdlib=libc++-o test.cpp
$clang++-std=c++0x-stdlib=libstdc++-o test.cpp
test.cpp:10:22:错误:命名空间“std”中没有名为“minmax_元素”的成员
auto temp=std::minmax_元素(x_array.begin(),x_array.end());
~~~~~^
生成1个错误。
使用cmake,可通过以下代码轻松实现设置:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
你使用的是哪一个C++库?你有没有包括<代码> <代码>?@ JuangopaZa?是的,我已经包括了你使用的编译器,你是否启用了C++ 11模式?@ TROJANFOE我使用苹果LLVM编译器4.2 C++语言方言编译器默认