3

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) ^

3 Answers3

2

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.

Kulfy
  • 17,696
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.

vidarlo
  • 22,691
0

To upgrade g++ to 11, try the following commands (with sudo permission):

add-apt-repository --yes ppa:ubuntu-toolchain-r/test
apt -qq install g++-11
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 10
kenorb
  • 10,347