bool IsValidInt(const CString& text, long& value)
{
LPCTSTR ptr = (LPCTSTR) text;
LPTSTR endptr;
value = _tcstol(ptr, &endptr, 10);
return (*ptr && endptr - ptr == text.GetLength());
}
bool IsValidFloat(const CString& text, double& value)
{
LPCTSTR ptr = (LPCTSTR) text;
LPTSTR endptr;
value = _tcstod(ptr, &endptr);
return (*ptr && endptr - ptr == text.GetLength());
}
Run Code Online (Sandbox Code Playgroud)
编辑:修改代码以遵循评论中提供的优秀建议.
| 归档时间: |
|
| 查看次数: |
2041 次 |
| 最近记录: |