https://rentry.org/PPP2_p162a

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

#include <iostream>
#include <vector>

using std::cout;
using std::vector;

int main()
{
  vector<double> v{1.1, 2.2, 3.3, 4.4, 5.5};

  // note: try un-commenting the code below (all at once) and fixing it:

  // int j = 5;

  // for (int i = 0; i <= max; ++j) {  // oops! (twice)
  //   for (int i = 0; 0 < max; ++i)   // print the elements of v
  //     ;
  //   cout << "v[" << i << "]==" << v[i] << '\n';
  //   // …
  // }
}

build & run:

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

PrevUpNext

Edit
Pub: 25 Feb 2023 11:36 UTC
Edit: 29 Apr 2023 09:58 UTC
Views: 617