5.10. String access operations PDF

Title 5.10. String access operations
Course Intermediate Programming Methodologies in C++
Institution De Anza College
Pages 9
File Size 533.7 KB
File Type PDF
Total Downloads 19
Total Views 149

Summary

5.10 String access operations
String character indices
A string is a sequence of characters in memory. Each string character has a position number called an index, starting with 0 (not 1)....


Description

2/18/2021

5.10. String access operations

5.10 String access operations String character indices A string is a sequence of characters in memory. Each string character has a position number called an index, starting with 0 (not 1). PARTICIPATION ACTIVITY

Start

5.10.1: A string's characters each has an index, starting with 0.

2x speed Index

"Mary"

Captions

M

0

a

1

r

2

y

3



1. A string is a sequence of characters. So "Mary" is a sequence of characters M, a, r, y. 2. Each character has an index, starting with 0 (not 1). For a four-character string like "Mary", M is at index 0, a at 1, r at 2, and y at 3. A 4-character string's last index is 3, not 4. Feedback?

PARTICIPATION ACTIVITY

5.10.2: String indices.

1) For string "Light", what is L's index? 0 1 2) For string "Light", what is i's index? 0 1 2 3) For string "Light", what is t's index? 4 5 4) For string "Oh my", which character is at index 2? https://learn.zybooks.com/zybook/DEANZACIS22BGarbaceaWinter2021/chapter/5/section/10

1/9

2/18/2021

5.10. String access operations

h (space) m 5) For string "You wish!", which character is at index 4? (space) w 6) For string "You wish!", which character is at index 9? h ! " No such character Feedback?

Accessing string characters at(): The notation someString.at(x) accesses the character at index x of a string.

Figure 5.10.1: String character access: Word scramble. #include #include using namespace std; int main() { string userWord;

Enter a 5-letter word: water Scrambled: earwt

cout > userWord; cout cout cout cout cout cout cout...


Similar Free PDFs