xcode 如何更新我的编译器以使用C++11特性?

zdwk9cvp  于 12个月前  发布在  其他
关注(0)|答案(4)|浏览(181)

我试着让自己进入C++,并购买了Bjarne Stroustrup的《编程-使用C++的原理和实践》一书。
当我试图获取编译以下源代码:

#include "std_lib_facilities.h"
int main(){
    cout<<"Hello, World!\n";
    keep_window_open();
    return 0;
}

字符串
我得到以下编译错误:

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约塞米蒂),并试图编译与xCode和textmate.我甚至试图按照本教程(https://wiki.helsinki.fi/display/HUGG/Installing+the+GNU+compilers+on+Mac+OS+X),但它没有帮助.(至少当我试图编译与文本伴侣)
希望你能帮到我:)

4c8rllxm

4c8rllxm1#

如果你在Mac或Linux上,编译器通常是g或clang;要访问C11,只需在调用编译器时指定-std=c++11作为选项(假设你有最新版本)。

e37o9pze

e37o9pze2#

你需要做的是打开项目设置->构建设置,将 C++ 方言设置为C11,将C标准库设置为libc++(LLVM C标准库支持C11)。

icnyk63a

icnyk63a3#

从构建设置中,将** C++ 方言**调整为C++11..


的数据
另外,请确保您使用的是LLVM C库,因为它完全支持C 11。

daupos2t

daupos2t4#

转到Settings => User =>搜索Run Code Configuration =>按Edit in settings.json


的数据
在这里只需找到code-runner.executorMap并在其中添加-std=c++11版本,类似于:

"code-runner.executorMap":{
    "cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},

字符串

相关问题