Variables & Data Types

User Input

Read user input with

std::cin
.

Basic Input

#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;
}

Full Line Input

Use

getline()
for strings with spaces:

std::string fullName;
std::cout << "Enter full name: ";
std::getline(std::cin, fullName);
Visualizer
$ ./calculator
Enter first number: 5 Enter second number: 3 Sum: 8

Interactive Visualization

c
Loading...
Output
Run execution to see output...