在C++中使用stod函数可以将字符串转换为double类型。示例如下:
#include <iostream>
#include <string>
int main() {
std::string str = "3.14159";
double d = std::stod(str);
std::cout << "String " << str << " converted to double: " << d << std::endl;
return 0;
}
在此示例中,std::stod
函数将字符串"3.14159"转换为double类型,并将结果存储在变量d中。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:如何在c++中使用unicode字符串