Back to slide -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'          strings/knold-tot.cc - The Knold & Tot example from section 20.3.6 of 3rd version of the C++ book.Lecture 3 - slide 12 : 27
Program 1

// From Stoustrup, The C++ Programming Language, 3ed ed, page 588.
// Illustrates value semantics of C++ strings.

#include <iostream>
#include <string>

void g(){
  std::string s1{"Knold"},
              s2{"Tot"};

  s1 = s2;            // Now s2 is "Tot" and s1 is another copy of "Tot".
  s2[1] = 'u';        // s2 is mutated. Now "Tut".

  std::cout << s1 << " og " << s2 << std::endl;             // Tot og Tut
}

int main(){
  g();
}