isdigit函数用法、获得字符串对应的数字

1.isdigit函数用法

语法:

#include <ctype.h>

int isdigit( int ch );

使用需要添加头文件#include <ctype>

功能:

如果参数是0到9之间的数字字符,函数返回非零值,否则返回零值。

2.GetNUmber

//获得字符串对应的数字
double GetNumber(string str, int index) {
    double number = 0;
    while(isdigit(str[index])) {
        number = number * 10 + str[index] - '0';
    }
    return number;
}
posted @ 2024-02-24 16:43  paopaotangzu  阅读(157)  评论(0)    收藏  举报