to_string在C++中无法使用?

很多场合需要将一些基本数据类型转化成字符串,java中有toString方法,C++中也有to_string函数调用,包含文件为

具体用法可以看这里:to_string,测试例子:

// to_string example
#include    // std::cout
#include      // std::string, std::to_string

int main ()
{
  std::string pi = "pi is " + std::to_string(3.1415926);
  std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";
  std::cout << pi << '\n';
  std::cout << perfect << '\n';
  return 0;
}

 

但是博主在使用Clion编辑程序的时候,发现住哪好要求包含了文件,但是编辑器报错。

 

 

经过查询发现是MinGW本身的问题,目前已经解决,特给出解决方案:

1. 下载补丁,mingw-to-string-gcc47.zip to_string补丁 或者 http://tehsausage.com/mingw-to-string,其中包含三个文件夹wchar.h, stdio.h, os_defines.h


2. 将补丁包中的wchar.h 和 stdio.h复制到mingw安装路径下[%路径%]\mingw\include,覆盖掉原来的。如果找不到mingw的安装路径,可以查看你的IDE里的配置,例如clion中为设置下>>工具链>>环境中。

to_string在C++中无法使用?_第1张图片

to_string在C++中无法使用?_第2张图片
3.将补丁包中的os_defines.h ,拷贝到[%路径%]\mingw\lib\gcc\mingw32\4.7.0\include\c++\mingw32\bits下。


4.修复完毕。

to_string在C++中无法使用?_第3张图片

 

假如按照步骤没有修复,可以看这里:stackoverflow:https://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-g-mingw

 

你可能感兴趣的:(to_string在C++中无法使用?)