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

系统 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级讲师

모든 응답(1)
刘奇

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

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

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

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!