C++20 sections · 1024 units
Open in Course

Hello Name - Implementation

Complete solution

#include <iostream>
#include <string>
using namespace std;

int main() {
 // Declare variable to store name
 string userName;
 
 // Ask user for input
 cout << "What is your name? ";
 
 // Read name from keyboard
 cin >> userName;
 
 // Print greeting with name
 cout << "Hello, " << userName << "!" << endl;
 
 return 0;
}
``` The cin statement waits for you to type something and press Enter, storing your input in userName. Then cout builds the greeting by chaining together fixed text and the variable content.