Determining if a string is a double

前端 未结 5 712
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 01:38

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          


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 02:27

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

提交回复
热议问题