OOP2 Strings Flashcards
What type of data type is the string type?
Programmer defined type, not part of base C++
What library do you need to access std::string data type?
include <string></string>
What terminators do you need for strings?
“ … “
What are strings called with no characters?
Null/empty strings
What does length function do for std::string?
Returns unsigned int of how many chars are in string
What does size function do?
Returns unsigned int value of amount of chars in the string, same as .length() but works also with vector, arrays etc
What type is the unsigned int returned by length, size, etc?
std::string::size_type
What does .find() do?
Find returns an int of type string::size_type corresponding to the index of the string where the first char of the passed string was matched
What argument does .find() take?
It takes a substring to be found in the operated string
Find is case sensitive, true or false?
True
What happens if .find() finds no match?
Returns an named const of type string::npos
What happens if there are multiple identical subtrings for .find() to find?
Considers only the first
What does .substr() do?
Returns the piece of the string that starts at the specified index and continues for the number of chars specified
What arguments does .substr() take?
Substring takes two integers, first is starting index, second is length of sub string
Where does substring start counting from for length of returned string?
1 counted from same index as first argument