确定字符串是否为双精度 [英] Determining if a string is a double

查看:103
本文介绍了确定字符串是否为双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看一个字符串是否包含双重的唯一内容。换句话说,如果可能是以下函数的输出:

I would like to see if a string contains a double as its sole contents. In other words, if it could possibly be the output of the following function:

string doubleToString(double num)
{
    stringstream s;
    s << num;
    return s.str();
}


推荐答案

你想要 strtod 函数。

bool isOnlyDouble(const char* str)
{
    char* endptr = 0;
    strtod(str, &endptr);

    if(*endptr != '\0' || endptr == str)
        return false;
    return true;
}

这篇关于确定字符串是否为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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