String and Arrays
String and Arrays
String and
Arrays
Source: Modern C++ for Absolute Beginners by Slobodan Dmitrović
C A M A R I N E S S U R P O LY T E C H N I C C O L L E G E S | C O L L E G E O F C O M P U T E R S T U D I E S
Introduction to String
String
To use string type, we need to include the <string> header in our
program:
String
We can add a string literal to our string using the compound
operator += :
String
We can add another string to our string using the + operator. We
can say we concatenate strings:
String
Preferred way of accepting a string from the standard input is via
the getline function which takes cin and the string as parameters:
Arrays
Source: Modern C++ for Absolute Beginners by Slobodan Dmitrović
C A M A R I N E S S U R P O LY T E C H N I C C O L L E G E S | C O L L E G E O F C O M P U T E R S T U D I E S
Array
Arrays
Arrays are sequences of objects of the same type. We can declare
an array of type char and as follows:
Array Indices 0 1 2 3 4