error: ‘to_string‘ is not a member of ‘std‘ 或 error: ‘thread‘ is not a member of ‘std‘ 原因及解决办法

简介: error: ‘to_string‘ is not a member of ‘std‘ 或 error: ‘thread‘ is not a member of ‘std‘ 原因及解决办法

一、错误描述

昨天在编译 paho.mqtt.cpp-1.0.1 时出错,提示 error: 'to_string' is not a member of 'std' ,

在网上看了一下,类似的错误还有:

error: 'to_string' is not a member of 'std'
error: 'thread' is not a member of 'std'

二、原因分析

因为 to_string 和 thread 是 C++11 才支持的,所以出现这种错误的原因可能是编译时漏了支持 C++11 的编译选项。


三、解决办法

3.1 一般情况在编译选项加上 -std=c++11 或 -std=gnu++11。

3.2 如果是使用 cmake 生成 Makefile 的,需要检查 CMakeLists.txt 文件的 C++11配置,加上如下几句代码

## --- C++11 build flags ---
add_definitions(-D_GLIBCXX_USE_C99=1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


目录
相关文章
|
1月前
|
C++
C++ std::string类的使用
C++ std::string类的使用
22 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Error: Element type is invalid: expected a string (for built-in components) or a class/function
2312 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
|
5月前
|
编译器
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
91 1
|
6月前
|
C++
std::string 不能跨dll的一种解决方法
std::string 不能跨dll的一种解决方法
|
6月前
|
C++
MFC exe使用C++ dll中的std::string 崩溃
MFC exe使用C++ dll中的std::string 崩溃
VC7(VS2002)调试时 std::string 超过15字符乱码问题
VC7(VS2002)调试时 std::string 超过15字符乱码问题
|
7月前
Uniapp Syntax Error: Error: Unbalanced delimiter found in string
Uniapp Syntax Error: Error: Unbalanced delimiter found in string
120 0
|
7月前
|
传感器 IDE 开发工具
排错实战 —— 解决 c++ 工程编译错: error C2059 'string' illegal token on right
排错实战 —— 解决 c++ 工程编译错: error C2059 'string' illegal token on right
|
7月前
C++17新特性之std::string_view
std::string_view系C++17标准发布后新增的内容,类成员变量包含两个部分:字符串指针和字符串长度,相比std::string, std::string_view涵盖了std::string的所有只读接口。如果生成的std::string无需进行修改操作,可以把std::string转换为std::string_view,std::string_view记录了对应的字符串指针和偏移位置,无需管理内存,相对std::string拥有一份字符串拷贝,如字符串查找和拷贝,效率更高。
C++17新特性之std::string_view
|
10月前
|
数据安全/隐私保护
fatal error: boost/algorithm/string.hpp: 没有那个文件或目录
fatal error: boost/algorithm/string.hpp: 没有那个文件或目录
123 0