How to configure g++ compiler in netbeans 8.1 correctly for c++11/c++14 support?

ε祈祈猫儿з 提交于 2019-12-12 03:26:53

问题


I'm a novice and work my way through Programming Principles and Practise using c++ by stroustrup ... I'm using Netbeans ide 8.1 and have a problem with the following:

#include "std_lib_facilities.h"
int main()
{
vector<int> v = {0,1,2,3,4,5,6};
for(int i = 0; i < v.size(); ++i)
    cout << v[i] << "\n";
}

If I compile, I get the error could not convert {0, 1, 2, 3, 4, 5, 6} from <brace-enclosed initializer list> to Vector<int> . I thought this has maybe something to do with missing compiler support for c++11 or 14, my compiler is g++ 4.8. Do I have to add anything to the compiler settings or is it another problem? Thanks


回答1:


Make sure you are using the new version of "std_lib_facilities.h" instead of the old one.




回答2:


Add the compiler flag -std=c++14 for c++ 14 and likewise -std=c++11 for c++ 11. Only add one of these flags to the build flags in your IDE.



来源:https://stackoverflow.com/questions/36324934/how-to-configure-g-compiler-in-netbeans-8-1-correctly-for-c11-c14-support

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!