Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lexical_cast int to string

Is it safe to ignore exception of boost::lexical_cast when converting int to std::string?

like image 665
dimba Avatar asked Apr 29 '10 09:04

dimba


People also ask

What is boost :: Lexical_cast?

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. Examples: Conversion integer -> string string- > integer integer -> char float- > string.

How does stoi work in C++?

In C++, the stoi() function converts a string to an integer value. The function is shorthand for “string to integer,” and C++ programmers use it to parse integers out of strings. The stoi() function is relatively new, as it was only added to the language as of its latest revision (C++11) in 2011.


1 Answers

Exception raised by lexical cast when converting an int to std::string are not associated to the conversion, but to resource unavailable. So you can ignore this in the same way you ignore the exception bad_alloc raised by operator new.

like image 181
Vicente Botet Escriba Avatar answered Oct 18 '22 22:10

Vicente Botet Escriba