πŸ“˜ Commonly Used

string::

Members

Below are useful std::string members you can access (either with string:: for static members or via an object for methods):

Type Name Purpose
string::npos npos Indicates β€œnot found” in search functions
string::value_type char Underlying type of characters
string::size_type size_t Type used for sizes and indexes

βœ… Common

std::string

Methods (non-static, so used via object)

While these don’t use string:: when called, they are part of the std::string class:

Method Use
s.find("x") Finds position of substring β€œx”
s.rfind("x") Finds last occurrence of β€œx”
s.substr(pos, len) Substring from position pos of length len
s.erase(pos, len) Erase len characters from pos
s.insert(pos, str) Insert str at position pos
s.replace(pos, len, str) Replace len characters at pos with str
s.empty() Checks if string is empty
s.size() or s.length() Get string length
s.push_back(c) / s.pop_back() Add/remove last character
s.clear() Empties the string
s.c_str() Get C-style null-terminated string