vendredi 1 mai 2015

Why don't gcc 4.8.1 support the new auto feature in c++11?

I use the gcc 4.8.1 compiler to compile my code, which use the new c++11 feature of auto. It is supposed that the auto keyword would automatically infer the data type. However, the compiler throw out an error :

   *** does not name a type

Here is my code:

#include<iostream>
#include<string>
using namespace std;

int main()
{

    string str="If you want to do it, try your best.";
    cout<<str<<endl;
    for(auto i:str){             //<-error here
        cout<<i<<endl;
    }


    return 0;
}

And the error is :

'i' does not name a type.....(of course there are some error message following)

And my compiler version is:gcc version 4.8.1(in MingW)

According to the gcc document, this version of gcc have already supported c++11, so why would this happen?

Aucun commentaire:

Enregistrer un commentaire