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.
11.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) ^
2 Answers
Just add a flag and compile it using
g++ -std=c++11 1.cppExplanation:
0-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.
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.