From the course: Complete Guide to C++ Programming Foundations

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Terminal interaction

Terminal interaction

- [Instructor] It's time to write some code. In this exercise, our task is simple. Ask the name of the user and print a message addressing the user's name. For this, we'll need to use the standard libraries c in and c out objects. For this example, we'll use something similar to our Hello world. So, we'll start with the same code. Since we are going to get a string from the user, we'll need to include the string hi there file from the standard library in line six. Then in line nine, let me declare a string variable called name, which I'll use to hold the user input. Next, let me change the c outline to print the message asking for the user's name. Now, I would like the user input to appear in the same line of my prompt, so I will remove the end line and replace it with std flush. This makes sure that the output is completely sent to the terminal before waiting for the user input. And L does this by default, but I don't want to send the end line just yet. Next, we capture the user…

Contents