macos - C++的编译器的问题
PHP中文网
PHP中文网 2017-04-17 12:08:57
0
1
621

系统 Mac
编辑器 MacVim
编译器 clang++ 和 g++
IDE Xcode
在终端中编译失败,在Xcode中运行成功,为什么?
代码如下:

#include <iostream>
#include <string>
#include <vector>
//#include "t.h"
using namespace std;

int main()
{
    vector<string> v1={"hi"};
    vector<string> v2;
    v1.insert(v1.begin(),"hello");

    for(auto a:v1)
    {
        cout<<a<<endl;
    }
    return 0;
}

终端编译的界面如下
错误描述为

non-aggregate type 'vector<string>' cannot be initialized with an initializer list

clang++ 和 g++ 错误描述一样

但是在Xcode中成功运行了

求教……

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
刘奇

http://stackoverflow.com/questions/10408849/how-can-i-use-c-11-features-in-clang

The IDE has the option to automatically detect the new features of C++ 11, and the command needs to manually add control parameters.

g++ -std=c++11 t.cpp

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!