gpt4 book ai didi

c++ - 应该使用哪个函数将字符串转换为 long double?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:54:53 25 4
gpt4 key购买 nike

请注意,一般来说,double 不同于long double

strtod 将 string 转换为 double,但是将 string 转换为 long double 应该使用哪个函数?

最佳答案

在 C++03 中,使用 boost::lexical_cast,或者:

std::stringstream ss(the_string);
long double ld;
if (ss >> ld) {
// it worked
}

在 C99 中,使用 strtold

在 C89 中,使用 sscanf%Lg

在 C++11 中使用 stold

关于每个人接受的格式可能存在细微差别,因此请先检查详细信息...

关于c++ - 应该使用哪个函数将字符串转换为 long double?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7389322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com