C++出现to_string is not a member of std 或者 to_string was not declared in this scope的解决方法
2017-08-08 19:32
876 查看
C++在将整型、浮点型、长整型等数据类型转换为字符串时,可使用在<string>头文件包含的函数:to_string().
函数原型如下:
string to_string (int val);
string to_string (float val);
string to_string (double val);
string to_string (long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (long long val);
string to_string (long double val);
然而在codeblocks等编译环境中,有时候会出现上述问题,原因是mingw编译器不支持to_string()这个方法,这是它的一个bug。
解决方法(以codeblocks为例):
1.首先你要使用to_string()这个函数,必须让编译器支持C++11的标准,这个函数是C++11提出的,在CodeBlocks > Settings > Global compiler settings > Compiler Flags 中 勾选 Have g++ follow the C++11 ISO C++ language standard,然后点击下方的OK。
2.在此链接中下载 mingw-to-string-gcc47.zip 这个压缩包(http://tehsausage.com/mingw-to-string,可能需要翻墙)。
3.将压缩包解压后,复制wchar.h和stdio.h到你的codeblocks安装路径中的\mingw\include中,将它们替换掉。
再将os_defines.h复制到\mingw\lib\gcc\mingw32\4.x.x\include\c++\mingw32\bits即可运行。
参考文章:http://tehsausage.com/mingw-to-string
函数原型如下:
string to_string (int val);
string to_string (float val);
string to_string (double val);
string to_string (long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (long long val);
string to_string (long double val);
然而在codeblocks等编译环境中,有时候会出现上述问题,原因是mingw编译器不支持to_string()这个方法,这是它的一个bug。
解决方法(以codeblocks为例):
1.首先你要使用to_string()这个函数,必须让编译器支持C++11的标准,这个函数是C++11提出的,在CodeBlocks > Settings > Global compiler settings > Compiler Flags 中 勾选 Have g++ follow the C++11 ISO C++ language standard,然后点击下方的OK。
2.在此链接中下载 mingw-to-string-gcc47.zip 这个压缩包(http://tehsausage.com/mingw-to-string,可能需要翻墙)。
3.将压缩包解压后,复制wchar.h和stdio.h到你的codeblocks安装路径中的\mingw\include中,将它们替换掉。
再将os_defines.h复制到\mingw\lib\gcc\mingw32\4.x.x\include\c++\mingw32\bits即可运行。
参考文章:http://tehsausage.com/mingw-to-string
相关文章推荐
- Codeblocks编译C++出现to_string is not a member of std 或者 to_string was not declared in this scope的解决方法
- Dev-C++ “to_string is not a member of std” error- 已解决
- 安装fcgi时出现:error: ‘EOF’ was not declared in this scope解决方法
- string was not declared in this scope问题解决方法
- C++ 中error: ‘exit’ was not declared in this scope 的解决方法
- Qt中 error: 'to_string' is not a member of 'std'解决方法
- 关于g++ memcpy’ was not declared in this scope解决方法
- Android NDK编译C++ 'stoi' and 'to_string' is not a member of 'std'
- ‘hash_map’ was not declared in this scope的解决方法
- 【Qt】错误:'connect' was not declared in this scope 解决方法
- error: ‘exit’ was not declared in this scope 的解决方法
- mingw32-make+cmake:error: 'nullptr' was not declared in this scope解决方法
- error: ‘to_string’ was not declared in this scope
- error: ‘to_string’ is not a member of ‘std’———已解决
- error: ‘exit’ was not declared in this scope 的解决方法
- v4l2驱动摄像头 出现错误UINT64_C' was not declared in this scope 解决
- error: ‘exit’ was not declared in this scope 的解决方法
- [Error] 'exit' was not declared in this scope的解决方法
- error: 'EOF' was not declared in this scope的解决办法
- gcc inet_addr was not declared in this scope 解决