“ setprecision”不是“ std”的成员 [英] ‘setprecision’ is not a member of ‘std’

查看:611
本文介绍了“ setprecision”不是“ 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包含标头< iomanip> setprecision < limits> 用于 std: :numeric_limits 。这些引用告诉您要包​​含哪个标头。

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

这篇关于“ setprecision”不是“ std”的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆