O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required