C++20 sections · 1024 units
Open in Course

Hello Name - The Idea

Main approach

The main idea is to follow a simple three-step process. First, create a variable to store text. Second, use cin to read what the user types into that variable. Third, use cout to print a message that includes the stored value.

You'll use the string type for storing names because it handles text naturally. I'll declare the variable before reading input, giving it a name like 'userName' that describes what it contains.

When printing the greeting, I'll combine literal text like "Hello, " with the variable value. The cout statement can handle multiple parts separated by the insertion operator, building up the complete message piece by piece.