skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-string
This page is read only. You can view the source, but not change it.
# <string> **[<string>](https://en.cppreference.com/w/cpp/header/string)** provides `std::string` (mutable) and `std::string_view` (read-only, C++17). `std::string` is a dynamic array of characters with O(1) amortized append, O(1) random access, and utilities like `find()`, `substr()`, `replace()`. Use `std::string` for owned text; use `std::string_view` for non-owning references (parameters, returns). This example demonstrates string length queries, indexing, searching, and replacement operations. ```cpp // compile: g++ -std=c++11 -o stringexample stringexample.cpp // run: ./stringexample // description: string operations #include <string> #include <iostream> int main() { std::string s = "hello world"; std::cout << "length: " << s.length() << "\n"; std::cout << "at index 6: " << s[6] << "\n"; size_t pos = s.find("world"); std::cout << "found at: " << pos << "\n"; s.replace(0, 5, "goodbye"); std::cout << "after replace: " << s << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top