4.13. Putting It All Together
A StringN Class
Character strings (char *) must always have a NULL (\0) terminator. Whether you declare character strings as literals or build one on the fly, you're expected to terminate each string with a NULL byte. This arrangement gives you access to a wide variety of string library functions and lets you input or output strings easily. Suppose, however, you need to handle NULL bytes as data (common in database formats and communications protocols). For example, the statement
const char *p = "\0two nulls\0\n";
allocates 12 bytes of character data (including two NULL bytes). A simple output statement such as
cout << p; // doesn't display the data
fails to display this string properly. Moreover, the string ...
Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.