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 |
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 |