Ami*_*yan 4 c c++ parsing long-double
注意,一般来说,double
不同于long double
.
strtod
将字符串转换为double
,但应该使用哪个函数将字符串转换为long double?
Ste*_*sop 15
在C++ 03中,使用boost::lexical_cast
或:
std::stringstream ss(the_string);
long double ld;
if (ss >> ld) {
// it worked
}
Run Code Online (Sandbox Code Playgroud)
在C99中,使用strtold
.
在C89中,使用sscanf
与%Lg
.
在C++ 11中使用stold
.
关于每个人接受哪种格式可能存在细微差别,因此请先检查详细信息......
您已将问题标记为"C++",因此我将给您一个C++答案:
为什么不直接使用流?
std::stringstream ss(myString);
long double x;
ss >> x;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2283 次 |
最近记录: |