C++ decltype未在mingw g+中声明+;4.7.2
出于某种原因,在mingw上尝试用G++编译以下代码时C++ decltype未在mingw g+中声明+;4.7.2,c++,c++11,g++,mingw,C++,C++11,G++,Mingw,出于某种原因,在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 ) {
#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;
}
我已经检查过了,g++编译器的版本是4.7.2,除了将
decltype
更改为std::string::size\u type
?decltype
是c++11的一个特性之外,还有谁知道我如何解决这个问题。您需要这样调用gcc
g++ -std=c++11
@ctor尽量避免decltype,它并不像看上去那么好,基本上,当涉及到decltype时,标准并不能保证什么都没有。
g++ -std=c++11