Strings,Classes,and the String Class

Strings,Classes,and the String Class - Lecture 4 Strings...

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

View Full Document Right Arrow Icon
1 Lecture 4: Lecture 4: Strings, Classes, and the String Class Strings, Classes, and the String Class PIC 10A Todd Wittman What is a class? What is a class? A class is a suped-up data type that may have special member functions defined in a library. An object is a suped-up variable that is a particular instance of a class. int v; class_name o; data type variable class object •Typically, we access the member function of a class with a period after our object object_name . function_name (parameters)
Image of page 1

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

View Full Document Right Arrow Icon
2 Classes in This Class Classes in This Class •We’ve already seen a class in action: cin and cout are objects defined in the iostream library. •Today we’re going to learn about the string class. •On Wednesday we’ll learn how to use a graphics class to draw some pictures. •In November we’ll learn how to write our own classes. Sec 2.6 Sec 2.6 : The String Class : The String Class • A string is a class that can hold text, much like the primitive data types int/double hold numbers. • To use it, we have to include the string library # include <string> • The declaration is the same as for variables. string name; name = “My precious!\n”; • Note the string text can hold punctuation, spaces, and even escape characters.
Image of page 2
3 String I/O String I/O We can input & output strings just like variables. string name = “My\nprecious!\n”; cout << name; • Output: My precious! Just remember to include both the string and iostream libraries. # include <iostream> #include <string> String I/O String I/O To read multiple strings, they should be separated by a space or line break.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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