c++ string to float
时间: 2023-09-11 22:13:16 浏览: 183
string转float
To convert a C++ string to a float, you can use the `std::stof` function from the `<string>` library. Here's an example:
```cpp
#include <iostream>
#include <string>
int main() {
std::string str = "3.14";
float floatValue = std::stof(str);
std::cout << "Float value: " << floatValue << std::endl;
return 0;
}
```
In this example, the `std::stof` function takes the string `str` and converts it to a float value. The resulting float value can then be used as needed.
阅读全文