https://rentry.org/PPP2_p70a

// Code derived from Stroustrup's PPP2 book
// § 3.5 Assignment and initialization
// -beginning on p 70

#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::string;

int main()
{
  string a = "alpha";  // a starts out with the value “alpha”
  cout << a << '\n';   //

  a = "beta";         // a gets the value “beta” (becomes “beta”)
  cout << a << '\n';  //

  string b = a;  // b starts out with a copy of a’s value (that is, “beta”)
  cout << b << '\n';  //

  b = a + "gamma";  // b gets the value a+“gamma” (that is, “betagamma”)
  cout << b << '\n';  //

  a = a + "delta";  // a gets the value a+“delta” (that is, “betadelta”)
  cout << a << '\n';  //
}

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_03/main_p70a.cpp && ./a.out

PrevUpNext

Edit
Pub: 18 Jan 2023 05:14 UTC
Edit: 29 Apr 2023 06:17 UTC
Views: 745