Download presentation
Presentation is loading. Please wait.
Published byBenjamin Hunter Modified over 8 years ago
1
Programming Fundamentals
2
Today’s Lecture Multidimensional Arrays Arrays as Class Member Data Arrays of Objects C-Strings
3
Multidimensional Arrays
6
Passing Arrays to Functions
7
OUTPUT???
8
Arrays of Structures
11
Arrays as Class Member Data
13
Arrays of Objects
15
C-Strings
17
C-String Variables Each character occupies 1 byte of memory. An important aspect of C-strings is that they must terminate with a byte containing 0. This is often represented by the character constant ‘\0’, which is a character with an ASCII value of 0. This terminating zero is called the null character. When the << operator displays the string, it displays characters until it encounters the null character.
18
Avoiding Buffer Overflow
19
String Constants
20
Reading Embedded Blanks It turns out that the extraction operator >> considers a space to be a terminating character. Thus it will read strings consisting of a single word, but anything typed after a space is thrown away.
21
Reading Embedded Blanks To read text containing blanks we use another function, cin.get(). This syntax means a member function get() of the stream class of which cin is an object.
22
Reading Multiple Lines
23
Copying a String the Hard Way
24
Copying a String the Easy Way
25
Arrays of Strings
27
The Standard C++ string Class Standard C++ includes a new class called string. You can concatenate string objects with the + operator:
28
Defining and Assigning string Objects
29
Input/Output with string Objects
31
Finding string Objects
32
Questions???
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.