The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
Home Strings and things Containers for Strings | ||
Containers for Strings
We have seen five types of values---booleans, characters, integers, floating-point numbers and strings---but only four types of variables---bool, char, int and double. So far we have no way to store a string in a variable or perform operations on strings. In fact, there are several kinds of variables in C++ that can store strings. One is a basic type that is part of the C++ language, sometimes called "a native C string." The syntax for C strings is a bit ugly, and using them requires some concepts we have not covered yet, so for the most part we are going to avoid them. The string type we are going to use is called pstring, which is an open-source alternative to a type created specifically for the Computer Science AP Exam. The pclasses, as the entire group of open-source classes are called, can be found in the appendix section of this book. You can also visit their homepage at http://www.ibiblio.org/obp/pclasses/. You might be wondering what is meant by class. It will be a few more chapters before I can give a complete definition, but for now a class is a collection of functions that defines the operations we can perform on some type. The pstring class contains all the functions that apply to pstrings. Unfortunately, it is not possible to avoid C strings altogether. In a few places in this chapter I will warn you about some problems you might run into using pstrings instead of C strings.
|
||
Home Strings and things Containers for Strings |