[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppLexicalCast
It has similar syntax as other casts (e.g. static_cast).
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppLexicalCast
(C++) boost::lexical_cast
Function from the Boost C++ Library for converting (also: casting) between numbers and std::strings.It has similar syntax as other casts (e.g. static_cast).
int main() { { //Double to std::string conversion const double d = 123.456; const std::string s = boost::lexical_cast<std::string>(d); assert(s == "123.456"); } { //std::string to int conversion const std::string s = "1234"; const int i = boost::lexical_cast<int>(s); assert(i == 1234); } return 0; }
- include <cassert>
- include <string>
- include <boost/lexical_cast.hpp>
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
