12- strings Flashcards
string
specific constructs that are designed for processing sequences of characters
before using, include string header: #include <string>don’t use string.h
as well as using std::string;
string declaration: string mystr;
value assignment at declaration:
string mystr(”Hello”);
string mystr2=”Hello”;</string>
lexicographically
how strings are ordered
letters in the alphabet are in the increasing order
longer word (with the same characters) is greater than shorter word
size()
current string size (number of characters currently stored in string
length() is same
max_size()
maximum number of characters in string allowed on this computer
empty()
true if string is empty
insert(start, substring)
inserts substring starting from position start
string s=”place”;
cout «_space;s.insert(1, ”a”); // produces ”palace”
replace (start, number, substring)
replaces number of characters starting from start with substring the number of characters replaced need not be the same
string s=”Hello”;
s.replace(1,4, ”i, there”); // produces ”Hi, there”
append(string2)
appends string2 to the end of the string
erase(start, number)
removes number of characters starting from start