11+-+Strings - Engineering101 Strings QuoteoftheDay 't...

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

View Full Document Right Arrow Icon
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; occupation = “superhero”;
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
Comparing Strings s < s2 Evaluates alphabetic order s > s2 s == s2 s <= s2 s >= s2 n Note, however, that upper and lowercase letters are  considered different.  Uppercase letters come before  lowercase letters alphabetically.   n Spaces and other characters are counted also.
Background image of page 9

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

View Full DocumentRight Arrow Icon
n Reads a whole line from an input stream,  stores in a string n Useful for extracting input with whitespace Operation Leading  whitespace Termination  condition Consumes  terminating  character? >> skipped
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 / 33

11+-+Strings - Engineering101 Strings QuoteoftheDay 't...

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