https://rentry.org/PPP2_p161

// Code derived from Stroustrup's PPP2 book
// § 5.9.1 Practical debug advice
//  -and beginning on p 161

#include <iostream>

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

// int f(int a)
// {
//   if (a > 0) { /* do something */
//     else
//     { /* do something else */
//     }
// }  // oops!

int main()
{
  // note: try un-commenting all this code (one part at a time) and fixing it:

  // cout << "Hello, << name << '\n'; // oops!

  // cout << "Hello, " << name << '\n; // oops!

  // if (a<=0 // oops!
  // x = f(y);

  // int count; /* . . . */ ++Count; // oops!
  // char ch; /* . . . */ Cin>>c; // double oops!

  // x = sqrt(y)+2 // oops!
  // z = x+3;
}

build & run:

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

PrevUpNext

Edit
Pub: 24 Feb 2023 13:08 UTC
Edit: 29 Apr 2023 10:02 UTC
Views: 389