如何更新我的编译器以使用C ++ 11功能? [英] How do I update my compiler to use C++11 features?
问题描述
我试图进入C ++,并购买了Bjarne Stroustrup的《编程-使用C ++的原理和实践》一书。
I tried to get myself into C++ and purchased the book "Programming - Principles and Practice Using C++" by Bjarne Stroustrup.
当我尝试编译以下源代码时:
When I tried to get compile the following source code:
#include "std_lib_facilities.h"
int main(){
cout<<"Hello, World!\n";
keep_window_open();
return 0;
}
我遇到以下编译错误:
I am getting following compile error:
In file included from /Users/hypertrooper/Documents/Programming - Principles and Practice Using C++/hello_world.cpp:1:
std_lib_facilities.h:71:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using size_type = typename std::vector<T>::size_type;
^
std_lib_facilities.h:102:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using size_type = std::string::size_type;
^
std_lib_facilities.h:107:8: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
std_lib_facilities.h:113:8: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
std_lib_facilities.h:213:107: error: expected '(' for function-style cast or type construction
inline int randint(int min, int max) { static default_random_engine ran; return uniform_int_distribution<>{min, max}(ran); }
~~~~~~~~~~~~~~~~~~~~~~~~~~^
std_lib_facilities.h:222:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Value_type = typename C::value_type;
^
std_lib_facilities.h:225:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Iterator = typename C::iterator;
^
6 warnings and 1 error generated.
我知道我的编译器未使用C ++ 11功能,但我不知道如何更新编译器,应该让我知道我使用的是MacOSX(10.10 Yosemite),并尝试使用xCode和d同伴。我什至试图遵循本教程( https ://wiki.helsinki.fi/display/HUGG/Installing+the+GNU+compilers+on+Mac+OS+X ),但没有帮助。 (至少当我尝试使用text mate进行编译时)
I get it that my compiler is not using C++11 feature, but I do not know how I can update the compiler. I should let know that I am using a MacOSX (10.10 Yosemite) and tried to compile with xCode and textmate. I even tried to follow this tutorial(https://wiki.helsinki.fi/display/HUGG/Installing+the+GNU+compilers+on+Mac+OS+X), but it did not helped. (At least when I tried to compile with text mate)
我希望您能够为我提供帮助。 :(
I hope you are able to help me. :(
推荐答案
您需要做的是打开项目设置->构建设置,并将C ++语言方言设置为C ++。 11和C ++标准库到libc ++(支持C ++ 11的LLVM C ++标准库)。
What you need to do is open the project settings -> Build Settings and set C++ Language Dialect to C++11 and the C++ Standard Library to libc++ (LLVM C++ standard library with C++11 support).
这篇关于如何更新我的编译器以使用C ++ 11功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!