https://rentry.org/PPP2_p121

// Code derived from Stroustrup's PPP2 book
// § 4.6.3 A numeric example
//  -and beginning on p 121

#include <iostream>
#include <vector>

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

// read some temperatures into a vector
int main()
{
  cout << "Please enter temperatures: ";
  vector<double> temps;            // temperatures
  for (double temp; cin >> temp;)  // read into temp
    temps.push_back(temp);         // put temp into vector

  // . . . do something . . .

  //---
  cout << '\n';

  // output above variable values to console...

  for (double temp : temps)
    cout << temp << '\n';
}

build & run:

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

PrevUpNext

Edit
Pub: 08 Feb 2023 01:47 UTC
Edit: 29 Apr 2023 08:41 UTC
Views: 476