chapter  14
44 Pages

Strings, Input/Output, and Visualization

For the most part, mathematical work does not involve manipulation of character data. Nonetheless, it is useful to have a general understanding of how C++ handles character data, how to convert text to numbers, how to use command line arguments, and how to read and write data in files. We also show how to modify the formatting of output (e.g., how to increase the number of digits printed after the decimal point). We illustrate many of these ideas by creating a class to parse files one line at a time, and break those lines into individual words. C++ has two ways to handle character data: arrays of char values and in objects

of type string. The char arrays are a legacy of C++’s roots in the C programming language. It is necessary to understand their basics, but their use should be avoided where possible. The newer string variables are easier to use. We begin with a brief introduction to char arrays. Textual and numerical output are important, but there are times when graphical

output is especially insightful. We close this chapter with a discussion of how to draw pictures in C++.