+ 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?
5 Answers
+ 1
Hereâs a simple solution:
std::string str = â0.827728262â;
double myDouble = atof(str.c_str());
+ 3
Much thanks @Kurwius : )
+ 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.
+ 1
@kurwius Thanks, thatâs horrible though :(