Programming Fundamentals
Today’s Lecture Multidimensional Arrays Arrays as Class Member Data Arrays of Objects C-Strings
Multidimensional Arrays
Passing Arrays to Functions
OUTPUT???
Arrays of Structures
Arrays as Class Member Data
Arrays of Objects
C-Strings
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.
Avoiding Buffer Overflow
String Constants
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.
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.
Reading Multiple Lines
Copying a String the Hard Way
Copying a String the Easy Way
Arrays of Strings
The Standard C++ string Class Standard C++ includes a new class called string. You can concatenate string objects with the + operator:
Defining and Assigning string Objects
Input/Output with string Objects
Finding string Objects
Questions???