Cygwin:g ++ 5.2:'to_string'不是'std'的成员

Ale*_*lex 5 c++ gcc cygwin c++11

以下简单程序无法使用gcc在cygwin中编译

#include <string>
#include <iostream>

int main()
{
  std::cout << std::to_string(4) << std::endl;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

命令行:

$ g++ -std=c++0x to_string.cc
Run Code Online (Sandbox Code Playgroud)

错误:

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;
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

可以在Ubuntu中编译相同的代码.

是否有可能使用cygwin编译此代码或者我需要编写一个解决方法?

Sim*_*mer -2

你在这里混合了 gcc 和 g++

引用Mike F:“它们的默认值中最重要的区别可能是它们自动链接到哪些库。”

g++ 和 gcc 有什么区别?

  • 他显然使用g++来编译该文件,请参阅他的命令行。所以这应该是完全没问题的。 (3认同)