diff --git a/lexical_cast.htm b/lexical_cast.htm index 4bbdc8e..efc7219 100644 --- a/lexical_cast.htm +++ b/lexical_cast.htm @@ -196,38 +196,60 @@ public: failure.
Q: Why does lexical_cast<int8_t>("127")
throw bad_lexical_cast
?
-
A: The type int8_t
is a typedef to char
or signed char
.
+
Question: | +Why does lexical_cast<int8_t>("127") throw bad_lexical_cast ? |
+
Answer: | +The type int8_t is a typedef to char or signed 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 as numeric_cast<int8_t>(lexical_cast<int>("127"));+ |
+
Question: | What does lexical_cast<std::string> of an int8_t or uint8_t not 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::skipws flag of an underlying stream object. It breaks my operator>> that works only in presence of this flag. Can you remove code that resets the flag? |
+
Answer: | +May be in a future version. There is no requirement in [N1973] to reset the flag but remember that [N1973] is not yet accepted by the committee. By the way, it's a great opportunity to make your operator>> conform to the standard. Read a good C++ book, study std::sentry and ios_state_saver.
+ |
+
Q: What does lexical_cast<std::string>
of an int8_t
or uint8_t
not do what I expect?
-
A: 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));- -
Q: The implementation always resets the ios_base::skipws
flag of an underlying stream object. It breaks my operator>>
that works only in presence of this flag. Can you remove code that resets the flag?
-
A: May be in a future version. There is no requirement in [N1973] to reset the flag but remember that [N1973] is not yet accepted by the committee. By the way, it's a great opportunity to make your operator>>
conform to the standard. Read a good C++ book, study std::sentry
and ios_state_saver.
-
-
std::locale
if your program runs in the "C