簡體   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