Back to results for “STL”
C++ › Strings & string_view

What common operations does std::string provide?

Beginner

Answer

std::string offers size()/length(), empty(), indexing with [] or at() (bounds-checked), substr(), find()/rfind(), replace(), append()/+=, comparison operators, c_str() for a null-terminated C-string, and iteration. These cover most text-manipulation needs without manual memory handling.
std::string s = "hello world";
auto pos = s.find("world");     // 6
std::string w = s.substr(pos);  // "world"
Real-world example Parsing a filename uses find and substr to extract the extension safely.

Common follow-ups: What is the difference between [] and at()? | What does c_str() return?