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

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

问题描述

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

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();
}


推荐答案

=http://linux.die.net/man/3/strtod =nofollow> strtod 功能。

You want the strtod function.

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

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

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

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