[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppStrToDouble
You could also use the Boost C++ Library's lexical_cast:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppStrToDouble
(C++) Converting a std::string to a double
Use the function 'atof', meaning 'ASCII TO Float'.int main() { const std::string myString = "123.456"; const double myValue = atof(myString.c_str()); assert(myValue == 123.456); return 0; }
- include <string>
- include <cassert>
You could also use the Boost C++ Library's lexical_cast:
int main() { const std::string s = "123.456"; const double d = boost::lexical_cast<double>(s); assert(d == 123.456); return 0; }
- include <string>
- include <cassert>
- include <boost/lexical_cast.hpp>
Other code snippets
Converting a String to a double
Code links
- ::, scope operator
- #include
- string
- assert
- cassert (header file)
- int
- main
- char
- const
- std
- scope operator, ::
- double
- return
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
