home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,070 of 33,346   
   Ulrich Eckhardt to All   
   Re: Modification of trailing null charac   
   29 Mar 12 23:06:37   
   
   6c807434   
   From: ulrich.eckhardt@dominolaser.com   
      
   Am 28.03.2012 21:07, schrieb fred.l.kleinschmidt@gmail.com:   
   > Is there such a thing as a "trailing null character" in a std::string?   
   > A std::string is not the same as a C string.   
      
   Yes, there is a null character. The first hint for that is the c_str()   
   function, which at least requires according space somewhere. Also,   
   consider the given code snippet:   
      
   >>      std::string s;   
   >>      char&c = s[0];    // well-defined   
      
   Normally, s[0] is an out-of-range access, since the string is empty.   
   However, this is an explicit exception.   
      
   Note that in the older C++ standard, accessing this null pointer was   
   only allowed via the const overload of operator[], so the above would   
   have been an error. Instead, you would have needed this:   
      
   std::string s;   
   std::string const& cs = s;   
   char const& c = cs[0];   
      
      
   Uli   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca