CH09 - CHAPTER 9 Strings 9.3 THE STANDARD CLASS string 394...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CHAPTER 9 Strings 9.1 AN ARRAY TYPE FOR STRINGS 368 C-String Values and C-String Variables 369 Pitfall: Using = and == with C-strings 373 Other Functions in <cstring> 375 C-String Input and Output 379 9.2 CHARACTER MANIPULATION TOOLS 382 Character I/O 382 The Member Functions get and put 382 Example: Checking Input Using a Newline Function 385 Pitfall: Unexpected ’\n’ in Input 386 The putback , peek , and ignore Member Functions 388 Character-Manipulating Functions 390 Pitfall: toupper and tolower Return int Values 392 9.3 THE STANDARD CLASS string 394 Introduction to the Standard Class string 394 I/O with the Class string 396 Tip: More Versions of getline 401 Pitfall: Mixing cin >> variable ; and getline 401 String Processing with the Class string 402 Example: Palindrome Testing 406 Converting between string Objects and C-Strings 411 Chapter Summary 411 Answers to Self-Test Exercises 412 Programming Projects 415
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9 Strings Polonius: What do you read my lord? Hamlet: Words, words, words William Shakespeare, Hamlet INTRODUCTION This chapter discusses two types whose values represent strings of characters, such as "Hello" . One type is just an array with base type char that stores strings of characters in the array and marks the end of the string with the null character, ’\0’ . This is the older way of representing strings, which C++ inherited from the C programming language. These sorts of strings are called C-strings . Although C-strings are an older way of repre- senting strings, it is difficult to do any sort of string processing in C++ without at least passing contact with C-strings. For example, quoted strings, such as "Hello" , are implemented as C-strings in C++. The ANSI/ISO C++ standard includes a more modern string handling facility in the form of the class string . The class string is the second string type that we will discuss in this chapter. The full class string uses templates and so is similar to the template classes in the Standard Template Library (STL). Templates are covered in Chapter 16 and the STL is covered in Chapter 19. This chapter covers basic uses of the class string that do not require a knowledge of templates. This material does not require extensive knowledge of arrays, but you should be familiar with basic array notation, such as a[i] . Section 5.1 of Chapter 5 covers more than enough material about arrays to allow you to read the material of this chapter. This material also does not require extensive knowledge of classes. Section 9.1 on C-strings and Section 9.2 on character manipulation can be covered before Chapters 6, 7, and 8, which cover classes. However, before reading Section 9.3 on the standard class string , you should read Chapter 6 and the following parts of Chapter 7: Section 7.1 and the subsection of Section 7.2 entitled The const Param- eter Modifier along with its accompanying pitfall section.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/10/2008 for the course CCS 115 taught by Professor _ during the Spring '08 term at NJIT.

Page1 / 54

CH09 - CHAPTER 9 Strings 9.3 THE STANDARD CLASS string 394...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online