https://rentry.org/PPP2_p64b

// Code derived from Stroustrup's PPP2 book
// § 3.3 Input and type
// -beginning on p 64

#include <iostream>
#include <string>

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

// read name and age (2nd version)
int main()
{
  cout << "Please enter your first name and age\n";
  string first_name = "???";  // string variable
                              // ("???” means “don’t know the name”)
  int age = -1;  // integer variable (-1 means “don’t know the age”)
  cin >> first_name >> age;  // read a string followed by an integer
  cout << "Hello, " << first_name << " (age " << age << ")\n";
}

build & run:

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

PrevUpNext

Edit
Pub: 17 Jan 2023 02:46 UTC
Edit: 29 Apr 2023 06:07 UTC
Views: 414