10.1
Character Testing
Character Testing
require cctype header file
FUNCTION isalpha isalnum isdigit islower isprint ispunct isupper isspace MEANING true if arg. is a letter false !ther"ise true if arg. is a letter !r digit false !ther"ise true if arg. is a digit 0#$ false !ther"ise true if arg. is l!"ercase letter false !ther"ise true if arg. is a %rinta&le character false !ther"ise true if arg. is a %unctuati!n character false !ther"ise true if arg. is an u%%ercase letter false !ther"ise true if arg. is a "hites%ace character false !ther"ise
10.)
Character Case C!n*ersi!n
10..
C#/trings
C#/trings
C#string, sequence !f characters st!red in ad0acent 'e'!r1 l!cati!ns and ter'inated &1 "#$$ character /tring literal 2string c!nstant3, sequence !f characters encl!sed in d!u&le qu!tes 4 4 , %Hi there!%
H i t h e r e ! &'
C#/trings
Arra1 !f chars can &e used t! define st!rage f!r string, const int ()*! = 2'; char city+()*!,; 5ea*e r!!' f!r "#$$ at end Can enter a *alue using cin !r -6 In%ut is "hites%ace#ter'inated 6 N! chec7 t! see if en!ugh s%ace
F!r in%ut c!ntaining "hites%ace and t! c!ntr!l a'!unt !f in%ut use cin.getline()
Copyright 2012 Pearson Education, Inc.
10.8
5i&rar1 Functi!ns f!r 9!r7ing "ith C#/trings
N!te, strcat and strcpy %erf!r' n! &!unds chec7ing t! deter'ine if there is en!ugh s%ace in recei*ing character arra1 t! h!ld the string it is &eing assigned.
Copyright 2012 Pearson Education, Inc.
10.:
C#/tring;Nu'eric C!n*ersi!n Functi!ns
< itoa d!es n! &!unds chec7ing 6 'a7e sure there is en!ugh s%ace t! st!re the result
Copyright 2012 Pearson Education, Inc.
10.<
Writing Your Own C-String Handling unctions
10.<
9riting =!ur O"n C#/tring >andling Functi!ns
10.A
M!re A&!ut the CBB string Class
string C!'%aris!n
Can use relati!nal !%erat!rs directl1 t! c!'%are string !&0ects,
string str1 = %>eorge%2 str2 = %>eorgia%; if (str1 < str2) cout << str1 << % is less than % << str2;
string O%erat!rs
O(E+ATO+ -<< = A= A +, -2 -=2 <2 <=2 ==2 != MEANING e@tracts characters fr!' strea' u% t! "hites%ace insert int! string inserts string int! strea' assigns string !n right t! string !&0ect !n left a%%ends string !n right t! end !f c!ntents !n left c!ncatenates t"! strings references character in string using arra1 n!tati!n relati!nal !%erat!rs f!r string c!'%aris!n. +eturn true !r false
string O%erat!rs
string word12 phrase; string word2 = % Bog%; cin -- word1; user enters %Hot 3amale% word1 has %Hot% phrase = word1 A word2; phrase has %Hot Bog% phrase A= % on a 6un%; for (int i = '; i < 1:; iAA) cout << phrase+i,; displays %Hot Bog on a 6un%