https://rentry.org/PPP2_p64a

// 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
int main()
{
  cout << "Please enter your first name and age\n";
  string first_name;  // string variable
  int    age;         // integer variable
  cin >> first_name;  // read a string
  cin >> age;         // read an integer
  cout << "Hello, " << first_name << " (age " << age << ")\n";
}

build & run:

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

PrevUpNext

Edit
Pub: 17 Jan 2023 02:37 UTC
Edit: 29 Apr 2023 06:03 UTC
Views: 645