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

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

View Full Document Right Arrow Icon
1 Chapter 7
Image of page 1

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

View Full Document Right Arrow Icon
2 Outline The string Class Character Manipulation Methods Exception Handling
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.
Image of page 3

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

View Full Document Right 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
Image of page 4
5 The string Class (continued)
Image of page 5

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

View Full Document Right Arrow Icon
6 The string Class (continued)
Image of page 6
7 The string Class (continued) Character positions within a string are numbered starting with zero
Image of page 7

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

View Full Document Right 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)
Image of page 8
9 The string Class (continued)
Image of page 9

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

View Full Document Right 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
Image of page 10
11 The string Class (continued) Three possible solutions to this problem: Do not use cin and getline inputs in the same program Follow the cin input with cin.ignore() Accept the Enter key into a character variable and then ignore it
Image of page 11

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern