Lec5 - Lecture 5: The String Class & User-Defined...

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

View Full Document Right Arrow Icon
1 Lecture 5: The String Class PIC 10A Todd Wittman 10/8/06 Recall classes. .. Last class we defined the concept of a class , which is a suped-up data type. An object is a particular instance of a class, just like a variable is an instance of a data type. primitive data type variable class object int variable_name; class_name object_name;
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 Recall strings. .. The string Class Revisited Returns starting position of substring s2 in s, starting search from position start of s. int s.find (string s2, int start) Deletes the substring from s starting at position start of length len. s.erase (int start, int len) Inserts string s2 into s at starting position start. s.insert (int start, string s2) Returns substring of s that starts at position start and has length len. string s.substr (int start, int len) Returns length of string s. int s.length( ) Constructor. Default string is “ “. Assign with string s =“word” string
Background image of page 2
3 Some Examples A Harder string Example Ex Take a long input string s, then find the first reference to “Star Wars” and replace it with “Lord of the Rings”. Enter your text: I love Star Wars!!! You meant to say: “I love Lord of the Rings!!!”
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 Revisited string s; string starwars = “Star Wars”; cout << “Enter your text: “;
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

Lec5 - Lecture 5: The String Class &amp; User-Defined...

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

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