Asks the user for a first and last name. Use the cin operator to retrieve data from the keyboard. - C++ Language Basics

C++ examples for Language Basics:Console

Description

Asks the user for a first and last name. Use the cin operator to retrieve data from the keyboard.

Demo Code

#include <iostream>
using namespace std;
int main()//from   w  ww .j av a  2 s .com
{
   char first[20];   // Holds the first name
   char last[20];    // Holds the last name
   cout << "What is your first name? \n";
   cin >> first;
   cout << "What is your last name? \n";
   cin >> last;
   // Print the initials
   cout << "Your initials are " << first[0] << " " << last[0];
   return 0;
}

Result


Related Tutorials