I just basically donβt understand why the line will not just end on the last char.
There are several ways to find out where the "last char" is:
- Keep the number of characters in a string separate from the characters in the string,
- Place a marker that indicates the last char of the line, or
- Keep the pointer to the last char of the string separate from line characters.
C select the second route; other languages ββ(Pascal, etc.) choose the first route. Some C ++ std::string implementations choose the third route * .
* Even
std::string implementations that use the first or third approach complete zero buffers for compatibility with parts of the C library. This is necessary to ensure that
c_str() returns a valid C string.
source share