繁体   English   中英

#包括 <iostream> 使用-std = c ++ 11给出错误

[英]#include <iostream> gives error using -std=c++11

我在Windows上使用MinGW的gcc编译器。 版本是4.9.3。 当将-std = c ++ 98,-std = c ++ 03或-std = c ++ 11用作参数时,以下代码给出错误。

#include <iostream>

int main()
{
    std::cout << "Hello world!" << std::endl;
    return 0;
}

当将-std = gnu ++ 98,-std = gnu ++ 03或std = gnu ++ 11用作参数时,代码编译没有错误。 另外,在不使用任何c ++版本参数的情况下,代码也不会错误编译(g ++ test.cpp -c)

在进一步调查中,我发现这是导致问题的#include。 使用任何std = c ++参数时,此代码均不会产生任何错误:

int main()
{
    return 0;
}

但是,当寻找其他东西来测试我的代码时,以下工作原理:

#include <cmath>
int main()
{
    return 0;
}

但这不是:

#include <string>
int main()
{
    return 0;
}

这是怎么回事? 通过对gnu ++的简短搜索,它说它提供了其他扩展,但是像上面的代码一样简单的代码肯定不应该依赖任何扩展吗?

我粘贴了使用g ++ test.cpp -c -std = c ++ 11编译第一段代码时发生的大错误。 http://pastebin.com/k0RLtWQz

第一条消息是:

$ g++ test.cpp -c -std=c++11
In file included from c:\mingw\include\wchar.h:208:0,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\cwchar:44,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\bits\postypes.h:40,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\iosfwd:40,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\ios:38,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\ostream:38,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\iostream:39,
                 from test.cpp:1:
c:\mingw\include\sys/stat.h:173:14: error: '_dev_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:\mingw\include\sys/stat.h:173:14: error: '_ino_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
…

通过更改为mingw64(也使用较新版本的gcc)来解决。 似乎问题出在我的mingw32安装或发行版上(如Jonathan Leffler所指出的)。 现在,所有-std = c ++ xx参数都可以使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM