11 Strings - Engineering101 ClicktoeditMastersubtitlestyle...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style Engineering 101 Strings
Background image of page 1

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

View Full DocumentRight Arrow Icon
Quote of the Day - Bill  Gates Success is a lousy teacher. It seduces smart people into thinking they can't  lose.  
Background image of page 2
The String Class n So far we have considered problems where the  data we are manipulating is primarily  numbers. n Often the data we want to work with is not  number, but rather  text .
Background image of page 3

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

View Full DocumentRight Arrow Icon
The String Class n The  string  class provides a way of  manipulating text objects. n To use the string class you must include it by  putting an include line at the top of your C++  program: #include <string>
Background image of page 4
Declaring a String n To declare a string: string firstname; n To assign a value to a string string firstname(“Peter”); or string firstname = “Peter”; n String literals are in “double-quotes”
Background image of page 5

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

View Full DocumentRight Arrow Icon
Assigning a String n You could do the same thing in two steps: string firstname; firstname = “Peter”;
Background image of page 6
Adding Strings n You can add strings together string firstname(“Peter”); string lastname(“Parker”); string fullname, occupation; fullname = firstname + “ “ + lastname;
Background image of page 7

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

View Full DocumentRight Arrow Icon
String Output n You can send strings to files and standard  output using  << cout << “Name : ” << fullname << endl; cout << “Job: “ << occupation << endl;
Background image of page 8
String Input n One function in the string class is useful for  reading a line of data: n getline will read a whole line from the  istream  in  and put it in  line n typically we don’t use the fact that getline 
Background image of page 9

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

View Full DocumentRight Arrow Icon
Comparing Strings s < s2 Evaluates alphabetic order s > s2 s == s2 s <= s2 s >= s2 n Note, however, that upper and lowercase letters are 
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

11 Strings - Engineering101 ClicktoeditMastersubtitlestyle...

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

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