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

Cygwin: g++ 5.2: ‘to_string’ is not a member of ‘std’

本文关键字:不是 std 成员 g++5 to Cygwin string      更新时间:2023-10-16

以下简单程序无法在带有gcc 的cygwin中编译

#include <string>
#include <iostream>
int main()
{
  std::cout << std::to_string(4) << std::endl;
  return 0;
}

命令行:

$ 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编译这些代码,或者我需要写一个变通方法?

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

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

g++和gcc之间有什么区别?