Getline from Console

Programming

This program demonstrates reading a full line of input (including spaces) from the console using std::getline().

Implementation

#include <iostream>
#include <string>

int main() {
    std::string name;
    std::cout << "Enter your name: ";
    std::getline(std::cin, name);
    std::cout << "Hello, " << name << "!" << std::endl;
    return 0;
}

Key Concepts

Example Interaction

Enter your name: John Doe
Hello, John Doe!