“setprecision”不是“std”的成员
Posted
技术标签:
【中文标题】“setprecision”不是“std”的成员【英文标题】:‘setprecision’ is not a member of ‘std’ 【发布时间】:2012-09-17 05:28:42 【问题描述】:错误:
~> 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;
【问题讨论】:
不包括string.h
...你的意思是string
还是cstring
?
顺便说一句,<limits>
需要 std::numeric_limits
。
请记住,您可以通过在 C++ 参考中查找标题来找到它们:setprecision
、numeric_limits
。
【参考方案1】:
您需要为std::setprecision 包含标题<iomanip>
,为std::numeric_limits 包含<limits>
。这些引用告诉您要包含哪个标头。
【讨论】:
以上是关于“setprecision”不是“std”的成员的主要内容,如果未能解决你的问题,请参考以下文章
cygwin g++ std::stoi“错误:‘stoi’不是‘std’的成员
std::thread 不是使用 Eclipse Kepler MinGW 命名空间 std 的成员