to_string在C++中无法使用?

来源:互联网 发布:电气设计软件有哪些 编辑:程序博客网 时间:2024/05/22 10:28

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

具体用法可以看这里:to_string,测试例子:
// to_string example#include <iostream>   // std::cout#include <string>     // std::string, std::to_stringint 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中为设置下>>工具链>>环境中。


3.将补丁包中的os_defines.h ,拷贝到[%路径%]\mingw\lib\gcc\mingw32\4.7.0\include\c++\mingw32\bits下。

4.修复完毕。



假如按照步骤没有修复,可以看这里:stackoverflow


原创粉丝点击