2015-11-03 62 views
5

以下簡單的程序不能在cygwin的用gccCygwin的:克++ 5.2: 'to_string' 不是

#include <string> 
#include <iostream> 

int main() 
{ 
    std::cout << std::to_string(4) << std::endl; 
    return 0; 
} 

命令行編譯 'STD' 的成員:

$ g++ -std=c++0x to_string.cc 

錯誤:

to_string.cc: In function ‘int main()’: 
to_string.cc:6:16: error: ‘to_string’ is not a member of ‘std’ 
    std::cout << std::to_string(4) << std::endl; 

G ++版本:

$ g++ --version 
g++ (GCC) 5.2.0 
Copyright (C) 2015 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

相同的代碼可以在Ubuntu中編譯。

是否有可能用cygwin編譯此代碼或我需要編寫一個解決方法?

+1

您可能需要使用'-std = C++ 11'代替'-std = C++ 0x' – NathanOliver

+1

@NathanOliver相同的結果。 – Alex

+0

您是否檢查過哪個''標頭被使用? –

回答

-1

你混合gcc和g ++這裏

引述Mike F:「在他們的默認設置可能最重要的區別是它們庫對自動鏈接。」

What is the difference between g++ and gcc?

+0

我編輯了我的問題。 – Alex

+3

他明顯使用g ++編譯該文件,請參閱他的命令行。所以這應該是完全沒問題的。 – leemes

+0

@leemes爲什麼你不檢查我的答案和亞歷克斯的編輯時間? –