std::string
Explanation
Dynamic character array. Similar to std::vector<char> but with string-specific operations.
See std::string.
Memory: usually heap-allocated, but small strings might be stored inline (SSO).
Time complexity:
| Operation | Complexity |
|---|---|
[], at | O(1) |
length()/size()/empty() | O(1) |
append() | O(k) where k = appended length |
substr() | O(k) where k = substring length |
compare() | O(n) |
Code
#include <print>
#include <string>
int main() {
std::string symbolName = "_main";
symbolName.append("_v2");
std::println("Contains 'main': {}", symbolName.contains("main"));
return 0;
}
Output
$ ./src/data-structures/build/std-string
Contains 'main': true