C++ “setprecision”不是“std”的成员
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12453557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:17:14 来源:igfitidea点击:
‘setprecision’ is not a member of ‘std’
提问by Aquarius_Girl
Errors:
错误:
~> 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:~>
Code:
代码:
#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;
}
回答by juanchopanza
You need to include header <iomanip>
for std::setprecisionand <limits>
for std::numeric_limits. These references tell you which header to include.
您需要包括标题<iomanip>
为的std :: setprecision和<limits>
对的std :: numeric_limits。这些引用告诉您要包含哪个标头。