“setprecision”不是“std”的成员
‘setprecision’ is not a member of ‘std’
>错误:
~> g++ ssstring.cpp
ssstring.cpp: In function ‘int main()’:
ssstring.cpp:12:31: error: ‘setprecision’ is not a member of ‘std’
ssstring.cpp:12:52: error: ‘numeric_limits’ is not a member of ‘std’
ssstring.cpp:12:74: error: expected primary-expression before ‘float’
ssstring.cpp:13:30: error: ‘setprecision’ is not a member of ‘std’
ssstring.cpp:13:51: error: ‘numeric_limits’ is not a member of ‘std’
ssstring.cpp:13:73: error: expected primary-expression before ‘float’
ssstring.cpp:14:28: error: ‘setprecision’ is not a member of ‘std’
ssstring.cpp:14:49: error: ‘numeric_limits’ is not a member of ‘std’
ssstring.cpp:14:71: error: expected primary-expression before ‘float’
anisha@linux-trra:~>
法典:
#include <sstream>
#include <iostream>
#include <string.h>
int main ()
{
// Convert `lat`, `lons`, and `vehicleId` to string.
float selectedPointLat = 2.2;
float selectedPointLng = 2.3;
float vehicleId = 1.0;
std :: stringstream floatToStringLat, floatToStringLng, floatToStringVehicleId;
floatToStringLat << std :: setprecision (std :: numeric_limits<float> :: digits10 + 1); floatToStringLat << selectedPointLat;
floatToStringLng << std :: setprecision (std :: numeric_limits<float> :: digits10 + 1); floatToStringLng << selectedPointLng;
floatToStringVehicleId << std :: setprecision (std :: numeric_limits<float> :: digits10 + 1); floatToStringVehicleId << vehicleId;
}
您需要为 std::
setprecision 包含标头 <iomanip>
,为 std::numeric_limits 包含标头 <limits>
。这些引用告诉您要包含哪个标头。
相关文章:
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- 将另一个类的对象传递到当前类C++的构造函数中(不是成员初始化)
- 在这种情况下,如何传递成员函数而不是函数?
- 无法将字符串数组声明为类成员而不是字符 (C++)
- FreeFileSync C++错误:'byte'不是 'std' 的成员
- "迭代器"和"const_iterator"不是 STL 容器的必需成员?
- Boost 绑定和"result_type":不是成员,对 c++03 友好
- basic_thread_pool 不是 boost::executors 的成员
- 如何解决 ReLU 不是构建时火炬::nn 错误的成员?
- "new"创建的实例的所有成员变量是否都存在于堆上而不是堆栈上?
- 获取 C2039:"交换":不是成员错误,如何解决?
- 使用静态成员函数而不是普通函数是否有任何开销?
- 使用派生类中的静态成员而不是基类
- 无法从好友功能访问类的私有成员?"ostream"不是"std"的成员?
- C++ 成员不是变量,而只是数据类型的名称吗?
- 'generate'不是窗口头文件中'std::random_device'的成员<random>
- 枚举成员不是类型错误
- Clang声称通用lambda参数的constexpr成员不是constexpr
- 静态类成员不是与 this 指针没有关联吗?
- "要求成员'*******'不是结构或工会"是什么意思?