Skip to content
techsnow

C++ Basics

Input and Output

#include <iostream>
#include <string>
using namespace std;

int main() {
    string name;
    int a, b;

    cout << "Your name: ";
    cin >> name;
    cout << "Two numbers: ";
    cin >> a >> b;

    cout << "Hi " << name << ", the sum is " << a + b << endl;
}

Output

Your name: Sara
Two numbers: 4 6
Hi Sara, the sum is 10