Boost.LexicalCast which is defined in the Library “boost/lexical_cast.hpp” provides a cast operator, boost::lexical_cast, that can convert numbers from strings to numeric types like int or double and vice versa.
boost::lexical_cast is an alternative to functions like std::stoi(), std::stod(), and std::to_string(), which were added to the standard library in C++11.
Now let see the Implementation of this function in a program.
Conversion integer -> string string- > integer integer -> char float- > string
Associated exceptions : If a conversion fails, an exception of type bad_lexical_cast, which is derived from bad_cast, is thrown. It throws an exception because the float 52.50 and the string “GeeksforGeeks” cannot be converted to a number of type int.
23 45 1234 Exception caught : bad lexical cast: source type value could not be interpreted as target Exception caught :bad lexical cast: source type value could not be interpreted as target
Reference :- http://www.boost.org/
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Custom Jumble Word Game
- Comparator Class in C++ with Examples
- Complete Guide to Install C++17 in Windows
- Features of C++
- Draw a triangle in C++ graphics
- Implementation of lower_bound() and upper_bound() in List of Pairs in C++
- How to Setup VSCode with C, C++ and Python for Competitive Programming
- Java System.exit(0) vs C++ return 0
- Features of C++17 with Examples
- Life cycle of Objects in C++ with Example
- Difference between virtual function and inline function in C++
- Difference between Turbo C++ and Dev C++
- Ellipsis in C++ with Examples
- Difference between Static and Dynamic Memory Allocation in C
- Const vs Regular iterators in C++ with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.