+ 1

[C++] Anyone having issues with std::stod() here on SoloLearn?

Alright, so std::stod() is a function that is part of the string header file / library. Its called via the std namespace though. Anyways, here's how it is used: #include <iostream> #include <string> int main() { double StringToDouble = std::stod("0.598372"); return 0; } This does NOT work here at SoloLearn in the code playground. You can test it out for yourself, although in every other compiler I can find it works perfectly fine. Anyone have a solution?

2nd Jan 2018, 6:48 PM
Giancarlo Forero
4 Respostas
+ 1
Here’s a simple solution: std::string str = “0.827728262”; double myDouble = atof(str.c_str());
3rd Jan 2018, 3:37 AM
Giancarlo Forero
+ 3
Much thanks @Kurwius : )
2nd Jan 2018, 8:56 PM
Ipang
+ 2
I once tried and failed to use std::stoi which also supposedly return a number, though unlike std::stod it returns int rather than floating number, and I couldn't get it to work either. I ended having to write my own string to integer function.
2nd Jan 2018, 8:36 PM
Ipang
+ 1
@kurwius Thanks, that’s horrible though :(
2nd Jan 2018, 8:51 PM
Giancarlo Forero