Chap7 - Chapter 7 1 Outline The string Class Character...

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

View Full Document Right Arrow Icon
1 Chapter 7
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline ± The string Class ± Character Manipulation Methods ± Exception Handling
Background image of page 2
3 The string Class ± Class: a user-created data type that defines a valid set of data values and a set of operations that can be used on them ± Object: storage area declared for a class ± string class permits string literals ± String literal: any sequence of characters enclosed in double quotation marks; also called string value, string, constant Figure 7.1 The storage of a string as a sequence of characters.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 The string Class (continued) ± string class provides functions for declaring, creating, and initializing a string ± Methods: functions in a class ± Constructor: the method which creates and initializes a string object ± string header file is required to use the string class
Background image of page 4
5 The string Class (continued)
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 The string Class (continued)
Background image of page 6
7 The string Class (continued) ± Character positions within a string are numbered starting with zero
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 The string Class (continued) ± Strings can be input from the keyboard and displayed on the screen using cout , cin , and getline ± getline continuously accepts and stores characters from the keyboard until the terminating key is pressed ± If the last argument is omitted, the Enter key will terminate the input Syntax: getline(cin, strObj, terminatingChar)
Background image of page 8
9 The string Class (continued)
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 The string Class (continued) ± Using cin and getline inputs together in the same program may cause problems ± cin accepts the input, but leaves the newline code from the Enter key in the buffer, which will be picked up by the getline as the end of its input
Background image of page 10
The string Class (continued) ± Three possible solutions to this problem: ± Do not use cin and getline inputs in the same program ± Follow the
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2009 for the course CSC 101 taught by Professor Betancourt during the Spring '09 term at CUNY City.

Page1 / 35

Chap7 - Chapter 7 1 Outline The string Class Character...

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

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