Home  >  Q&A  >  body text

macos - C++的编译器的问题

系统 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中文网2765 days ago625

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 12:10:57

    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

    reply
    0
  • Cancelreply