C++ Programming: Objects, RAII and the STL ยท C++ Basics
C++ strings grow by themselves and know their length. Join, measure, slice, search, change and compare them.
#include <iostream>
#include <string>
using namespace std;
int main() {
string first = "Grace";
string last = "Hopper";
string full = first + " " + last;
size_t len = full.length();
string part = full.substr(0, 5);
size_t where = full.find("Hop");
full[0] = 'g'; // strings in C++ can be changed in place
bool same = (part == "Grace");
cout << full << " " << len << " " << where << " " << same << endl;
return 0;
}int main().last is created on the stack with the value "Hopper".len is created on the stack with the value 12.grace Hopper 12 6 1.0.