Lecture 9 Flashcards
Literals
Specific fixed values of some type
Concatenation
When two things are combined without any spaces. + is the concatinatuon operator for string type variables.
Overload
When an operator has a different meaning for different variable types (e.g. + is concatenate for srings and addition for integers)
Operator overload
When an operator is overloaded
Append
When something is added to the end.
Strings
Variable type with text. String library needs to be #included. Text needs to be enclosed in double quotations.
Getline function
Allow us you to input data to a string type variable in the form:
Getline(in, variable name)
Rules for adding string literals and variables
Two string variables or a string variable and literal can be used, but adding two string literals may result in an error.
Char
Character variable type. Is a single number, letter, symbol, etc. Does not need to be #included. Value only needs to be enclosed in one quotation mark.
String relationship to vectors
Strong is an array or vector of characters with 0 in the last element to indicate the end of the string. This is why they can’t be added.
String functions
At and size can be used as well as length.
How strings are compared
Each character is compared and the first characters that are different are analyzed based on their ASCII number. The larger number is considered greater.
String member functions
- Empty() returns true if string is empty
- Find() searches for a string in another string and returns the location
- Substr() takes in arguments for starting position and length and returns the string at that location
- Replace() replaces part of a string with another string.