https://rentry.org/PPP2_p68b

// Code derived from Stroustrup's PPP2 book
// § 3.4 Operations and operators
// -beginning on p 68

#include <iostream>
#include <string>

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

// read and compare names
int main()
{
  cout << "Please enter two names\n";
  string first;
  string second;
  cin >> first >> second;  // read two strings

  if (first == second)
    cout << "that's the same name twice\n";

  if (first < second)
    cout << first << " is alphabetically before " << second << '\n';

  if (first > second)
    cout << first << " is alphabetically after " << second << '\n';
}

build & run:

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

PrevUpNext

Edit
Pub: 17 Jan 2023 06:51 UTC
Edit: 29 Apr 2023 06:15 UTC
Views: 693