From da5151abf6670ca4664380e7bd4556c25c154a5b Mon Sep 17 00:00:00 2001 From: Alexander Nasonov Date: Sun, 20 May 2007 16:25:34 +0000 Subject: [PATCH] added: FAQ and References section, updated: Changes [SVN r37725] --- lexical_cast.htm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lexical_cast.htm b/lexical_cast.htm index f55d741..2a08541 100644 --- a/lexical_cast.htm +++ b/lexical_cast.htm @@ -20,6 +20,10 @@ lexical_cast
  • bad_lexical_cast
  • +
  • + Frequently Asked Questions
  • +
  • + References
  • Changes
  • @@ -192,7 +196,39 @@ public: failure.
    +

    Frequently Asked Questions

    +

    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. + 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 int or short int. If bounds checking + is important, you can also call numeric_cast: + +

    numeric_cast<int8_t>(lexical_cast<int>("127"));
    + +

    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. + +

    References

    +

    Changes

    +

    August, October 2006:

    +

    June 2005: