【发布时间】:2011-05-03 16:08:11
【问题描述】:
我想在 C++ (Visual C++ 2010) 中使用 strtod 函数将字符串转换为双精度时检测下溢。尽管我是根据strtod 的文档执行的,但下面的代码并没有像我预期的那样工作:
char numStr[] = "123456.122111111123123123123132123123123123123124434345345";
char* pEnd;
double d = strtod(numStr, &pEnd);
int errorNum = errno;
if (errorNum == ERANGE) // this should be true
{
// underflow occurred
}
使用调试器,我发现errorNum 总是设置为0 而ERANGE 是34。
我错过了什么?
【问题讨论】:
标签: c++ c visual-c++ type-conversion