7. Strings: Analyzing the Text

Most computer programs, at some point in their lives, have to communicate with a human being. The standard way to do this is to use text strings; that’s especially true for the console-based applications in this book.

Using text strings to print simple messages is easy enough. Text strings get more interesting when you pick apart, combine, or analyze them. That’s what this chapter is all about.

Text Storage on the Computer

In Chapter 1, I said the computer stores text numerically, just like any other kind of data. But with text data, each byte uses a special code that corresponds to a particular character: This is called ASCII code. Suppose I declared the following string:

char *str = "Hello!";

C++ allocates exactly ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Second Edition 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.