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中成功运行了
图片描述

求教……

mac C++ g++ clang

萌喵小女仆 8 years, 9 months ago

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

IDE 有选项自动检测 C++ 11 的新特性,命令要手动添加控制参数。

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

七波白音丶 answered 8 years, 9 months ago

Your Answer