How to Convert String to Double in C++
In this tutorial, we are going to learn about how to convert the string to double in C++
To convert a string to double in c++, we can use the stod() function by passing a string as an argument to it.
Here is an example, that converts the string "90.556"
to an double.
#include <iostream>
#include <string>
using namespace std;
int main() {
string price = " 90.556 ";
double result = stod(price);
cout << "string (\"" << price << "\") is " << result << '\n';
}
Output:
string (" 90.556 ") is 90.556