0
0
C++programming~10 mins

String input and output in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
String input and output
📖 Scenario: You are creating a simple program that asks a user for their name and then greets them.
🎯 Goal: Build a program that takes a user's name as input and then prints a greeting message including their name.
📋 What You'll Learn
Use a string variable called name to store the user's input.
Use cin to read the user's name.
Use cout to print the greeting message.
💡 Why This Matters
🌍 Real World
Programs often need to get information from users and show messages back. This is the basic way to interact with people using a computer.
💼 Career
Knowing how to handle text input and output is essential for many programming jobs, especially when building command-line tools or simple user interfaces.
Progress0 / 4 steps
1
Create a string variable
Create a string variable called name to store the user's name.
C++
Need a hint?

Use std::string name; to create the variable.

2
Read user input
Use std::cin to read the user's name into the variable name.
C++
Need a hint?

Use std::cin >> name; to read the input.

3
Print greeting message
Use std::cout to print the message Hello, followed by the user's name and an exclamation mark.
C++
Need a hint?

Use std::cout << "Hello, " << name << "!" << std::endl; to print the greeting.

4
Run the program and see the output
Run the program and enter the name Alice. The program should print Hello, Alice!.
C++
Need a hint?

Type Alice when the program waits for input and press Enter.