Glam Prestige Journal

Bright entertainment trends with youth appeal.

how to upgrade gcc to c++11 in ubuntu? shall I face any problem after upgrading my present gcc? I am trying to run this code. `

int main()
{ using namespace std;
int n[5];
//cout << " please enter a character : ";
//cin >> x;
for(int m:n)
cout << m <<" ";
}

this is my warning.

1.cpp: In function ‘int main()’: 1.cpp:15:12: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11 for(int m:n) ^

1

2 Answers

Just add a flag and compile it using

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

Explanation:

-std=
    Determine the language standard. This option is currently only supported when compiling C or C++.

c++11
c++0x
    The 2011 ISO C++ standard plus amendments. The name c++0x is deprecated.

0

You compile it with g++ -std=c++11 or g++ -std=gnu++11 to tell the compiler that you want that standard. This is shown in the error message you have.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy