Chapter 4: Strings


OVERVIEW

In the teaching of C++ and Java, it is always difficult to decide when exactly to discuss the topic of strings. Consider, for example, the case of C++ strings. To fully understand this data type in C++, one has to have already been exposed to operator overloading, but operator overloading is best discussed after the notion of a class is fully aired. While we did provide a basic introduction to classes in Chapter 3, many more issues related to classes still need to be addressed—issues that sometimes are easier to understand if the string type is used to illustrate the examples (as we did for some of the definitions in Chapter 3).

We will therefore go ahead and and use this chapter to present the strings types in C++ and Java. The goal here is to only provide a level of familiarity with the string types that allows a reader to understand the examples in the chapters that follow. Additional information on the string types will be subsequently provided wherever the ongoing discussion makes it possible to do so.

Since it is possible to implement C++ string processing functions using the more generic C functions from the string.h header file of the C standard library,[1] this chapter will start with a very brief review of how strings are stored and processed in C. We will then discuss some of shortcomings of C-style strings, which will provide us with motivation for learning about strings in C++ and Java.

[1]For example, overload definitions for the ‘==,’ ‘<’, and ‘>’ operators used in the C++ string class could use the strcmp () function of C for comparing strings.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net