how to change a string to an float in c 2b 2b

Solutions on MaxInterview for how to change a string to an float in c 2b 2b by the best coders in the world

showing results for - "how to change a string to an float in c 2b 2b"
Alina
25 Jan 2017
1#include <iostream>
2#include <string>
3
4int main() {
5    std::string str = "123.4567";
6
7    // convert string to float
8    float num_float = std::stof(str);
9
10    // convert string to double
11    double num_double = std::stod(str);
12
13   std:: cout<< "num_float = " << num_float << std::endl;
14   std:: cout<< "num_double = " << num_double << std::endl;
15
16    return 0;
17}