Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

‘setprecision’ is not a member of ‘std’

Tags:

c++

string

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;  } 
like image 371
Aquarius_Girl Avatar asked Sep 17 '12 05:09

Aquarius_Girl


People also ask

What is std :: Setprecision?

std::setprecisionSets the decimal precision to be used to format floating-point values on output operations. Behaves as if member precision were called with n as argument on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams).

What C++ library is Setprecision in?

C++ iomanip Library - setprecision Function It is used to sets the decimal precision to be used to format floating-point values on output operations.

What does fixed Setprecision do in C++?

By using the setprecision function, we can get the desired precise value of a floating-point or a double value by providing the exact number of decimal places. If an argument n is passed to the setprecision() function, then it will give n significant digits of the number without losing any information.


1 Answers

You need to include header <iomanip> for std::setprecision and <limits> for std::numeric_limits. These references tell you which header to include.

like image 116
juanchopanza Avatar answered Sep 21 '22 12:09

juanchopanza