Re: [Boost-bugs] [Boost C++ Libraries] #7661: lexical_cast throws exception when strings have more than one null terminators

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #7661: lexical_cast throws exception when strings have more than one null terminators
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-11-09 14:54:11


#7661: lexical_cast throws exception when strings have more than one null
terminators
--------------------------------+-------------------------------------------
  Reporter: pengxu7@… | Owner: apolukhin
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: lexical_cast
   Version: Boost 1.52.0 | Severity: Problem
Resolution: | Keywords:
--------------------------------+-------------------------------------------

Comment (by marshall):

 A `std::string` is not a null terminated string.

 The string that you have constructed is two characters long. The first
 character is a '0' (ASCII 48), and the second is a NUL (ASCII 0).

 When you print that string, it prints _two_ characters - it's just that
 your console does not display the NULL.

 If you build this program and run it, you would see "m" printed on your
 console.
 {{{
 #include <iostream>
 int main( int argc, char *argv[] ) {
         std::string m = "0";
         m += '\0';
         std::cout << m;
 }
 }}}

 But if you redirect the output to a file, and look at the file, you will
 see that the file is two characters long, with the second being the NULL.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7661#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC