"Go" gcc/g++ how to support C11/C++11 standard compilation

Source: Internet
Author: User

123456789101112 /*    file : main.cpp*/#include <stdio.h>intmain() {    inta[5] = { 1, 2, 2, 5, 1 };    forint i:a ) {        printf"%d\n", a[i] );    }    return0;}

Then g++ will prompt the following error:

123 main.cpp: In function ‘intmain()’:main.cpp:5:13: error: range-based ‘for’ loops are not allowed in C++98 mode  forinti:a ) {

This means that the loop is not supported in c++98, because this is the c++11 new loop method.

So what if you have to compile it?

The following methods can be learned by ordering man g++:

g++-g-wall-std=c++11 main.cpp

In addition to g++, GCC can support C11 in a similar way

Gcc-g-wall-std=c11 main.cpp

What should I do if I don't want to write this-std=c++11 this option every time?

Method Source: HTTP://STACKOVERFLOW.COM/QUESTIONS/16886591/HOW-DO-I-ENABLE-C11-IN-GCC

Method 1: Write Makefile

Method 2: Alias: Alias g++11= "g++-std=c++11"

"Go" gcc/g++ how to support C11/C++11 standard compilation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.