https://rentry.org/PPP2_p118c

// Code derived from Stroustrup's PPP2 book
// § 4.6 vector
//  -and beginning on p 118

#include <iostream>
#include <string>
#include <vector>

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

int main()
{
  vector<int>    vi(6);  // vector of 6 ints initialized to 0
  vector<string> vs(4);  // vector of 4 strings initialized to ""

  // output above variable values to console...

  for (int i : vi)
    cout << i << '\n';

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

  for (string s : vs)
    cout << '"' << s << '"' << '\n';
}

build & run:

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

PrevUpNext

Edit
Pub: 08 Feb 2023 00:36 UTC
Edit: 29 Apr 2023 08:35 UTC
Views: 406