Read user input with
std::cin.
#include <iostream>
#include <string>
int main() {
std::string name;
int age;
std::cout << "Enter your name: ";
std::cin >> name;
std::cout << "Enter your age: ";
std::cin >> age;
std::cout << "Hello, " << name << "!" << std::endl;
return 0;
}
Use
getline() for strings with spaces:
std::string fullName;
std::cout << "Enter full name: ";
std::getline(std::cin, fullName);
Interactive Visualization