Strings

5.2 - Inputing a line of string using getline


In the previous lesson, using std::cin with the >> operator worked fine because the name was only one word. What if we need to input more than one word? We can use the std::getline function like this:

std::getline(std::cin, my_string);

This will input one line of text to my_string.

Task

Your task is to create a program which takes one line of text containing the user's full name and then prints out Greetings, <full name>!.

Sample input

Thomas Cat

Sample output

Greetings, Thomas Cat!
#include <iostream> #include <string> int main() { }