“setprecision”不是“std”的成员

‘setprecision’ is not a member of ‘std’

本文关键字:成员 不是 setprecision std      更新时间:2023-10-16

>错误:

~> 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>。这些引用告诉您要包含哪个标头。