- 
          Question: Why does lexical_cast<int8_t>("127")throwbad_lexical_cast?- 
                Answer: The type int8_tis atypedeftocharorsigned
                char. Lexical conversion to
                these types is simply reading a byte from source but since the source
                has more than one byte, the exception is thrown. Please use other
                integer types such asintorshort int.
                If bounds checking is important, you can also callboost::numeric_cast:numeric_cast<int8_t>(lexical_cast<int>("127"));
 
- 
          Question: Why does lexical_cast<unsigned char>("127")throwbad_lexical_cast?- 
                Answer: Lexical conversion to any
                char type is simply reading a byte from source. But since the source
                has more than one byte, the exception is thrown. Please use other
                integer types such as intorshort int.
                If bounds checking is important, you can also callboost::numeric_cast:numeric_cast<unsigned char>(lexical_cast<int>("127"));
 
- 
          Question: What does lexical_cast<std::string>of anint8_toruint8_tnot do what
          I expect?- 
                Answer: As above, note that int8_t
                and uint8_t are actually chars and are formatted as such. To avoid
                this, cast to an integer type first: lexical_cast<std::string>(static_cast<int>(n));
 
- 
          Question: The implementation always resets
          the ios_base::skipwsflag of an underlying stream object.
          It breaks myoperator>>that works only in presence of this flag. Can you remove code that resets
          the flag?
- 
          Question: Why std::cout << boost::lexical_cast<unsigned int>("-1");does not throw, but outputs 4294967295?- 
                Answer: boost::lexical_casthas the behavior ofstd::stringstream,
                which usesnum_getfunctions ofstd::localeto convert numbers. If we look at the Programming languages — C++,
                we'll see, thatnum_getuses the rules ofscanffor conversions. And in the C99 standard for unsigned input value
                minus sign is optional, so if a negative number is read, no errors
                will arise and the result will be the two's complement.
 
- 
          Question: Why boost::lexical_cast<int>(L'A');outputs
          65 andboost::lexical_cast<wchar_t>(L"65");does not throw?- 
                Answer: If you are using an old
                version of Visual Studio or compile code with /Zc:wchar_t- flag,
                boost::lexical_castsees singlewchar_tcharacter asunsigned short.
                It is not aboost::lexical_castmistake, but a limitation of compiler options that you use.
 
- 
          Question: Why boost::lexical_cast<double>("-1.#IND");throwsboost::bad_lexical_cast?- 
                Answer: "-1.#IND"is a compiler extension, that violates standard. You shall input"-nan","nan","inf","-inf"(case
                insensitive) strings to get NaN and Inf values.boost::lexical_cast<string>outputs"-nan","nan","inf","-inf"strings, when has NaN or Inf input values.
 
- 
          Question: What is the fastest way to convert
          a non zero terminated string or a substring using boost::lexical_cast?- 
                Answer: Use boost::iterator_rangefor conversion orlexical_castoverload with two parameters. For example, if you whant to convert
                tointtwo characters
                from a stringstr,
                you shall writelexical_cast<int>(make_iterator_range(str.data(), str.data() + 2));orlexical_cast<int>(str.data(),
                2);.