在mingw g ++ 4.7.2中,decltype未声明

cto*_*tor 4 c++ mingw g++ c++11

出于某种原因或其他原因,尝试在mingw上使用G ++编译以下代码

#include <iostream>
#include <string>
#include <cctype>

int main( int argc, char **argv )
{
    std::string s( "Hello, World!" );

    decltype( s.size(  ) ) punct_cnt = 0;

    for ( auto c : s )
    {
        if ( ispunct( c ) )
            ++punct_cnt;
    }

    std::cout << punct_cnt << " punctuation characters in " << s << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

test.cpp: In function 'int main(int, char**)':
test.cpp:9:23: error: 'decltype' was not declared in this scope
test.cpp:9:25: error: expected ';' before 'punct_cnt'
test.cpp:11:13: error: 'c' does not name a type
test.cpp:17:2: error: expected ';' before 'std'
test.cpp:17:15: error: 'punct_cnt' was not declared in this scope
test.cpp:19:2: error: expected primary-expression before 'return'
test.cpp:19:2: error: expected ')' before 'return'
Run Code Online (Sandbox Code Playgroud)

我已经检查和G ++编译器的版本是4.7.2,任何人有任何想法如何,我可以不是改变解决其他decltypestd::string::size_type

log*_*og0 7

decltype是一个c ++ 11功能.你需要这样调用gcc

g++ -std=c++11
Run Code Online (Sandbox Code Playgroud)