https://rentry.org/PPP2_p291

// Code derived from Stroustrup's PPP2 book
// § 8.6 Order of evaluation
//  -and beginning on p 291

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

using namespace std;

string program_name = "silly";

vector<string> v;  // v is global

void f()
{
  string s;  // s is local to f

  while (cin >> s && s != "quit") {
    string stripped;     // stripped is local to the loop only
    string not_letters;  //  "

    for (int i = 0; i < (int)s.size(); ++i)  // i has statement scope
      if (isalpha(s[i]))
        stripped += s[i];
      else
        not_letters += s[i];

    v.push_back(stripped);

    // . . .
  }

  // . . .
}

int main() {}

build & run:

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

PrevUpNext

Edit
Pub: 04 Apr 2023 15:11 UTC
Edit: 03 May 2023 00:42 UTC
Views: 334