c++ string to double
时间: 2023-09-11 09:03:32 浏览: 228
To convert a C++ string to a double, you can use the `std::stod` function from the `<string>` header. Here's an example:
```cpp
#include <iostream>
#include <string>
int main() {
std::string str = "3.14";
double num = std::stod(str);
std::cout << "Converted double value: " << num << std::endl;
return 0;
}
```
In this example, the `std::stod` function is used to convert the string `"3.14"` to a double value. The resulting value is stored in the variable `num` and then printed using `std::cout`.
阅读全文