33
Total Posts
3
Categories
24/7
Updated

C++

Write a C++ to illustrate the concepts of console I/O operations.

Published on Dec 22, 2025
#include <iostream>
#include <string>
using namespace std;

int main() {
    int age;
    float marks;
    string name;

    // Console Output
    cout << "Enter your name: ";
    getline(cin, name);   // Console Input (string)

    cout << "Enter your age: ";
    cin >> age;           // Console Input (integer)

    cout << "Enter your marks: ";
    cin >> marks;         // Console Input (float)

    // Console Output
    cout << endl;
    cout << "---- Student Details ----" << endl;
    cout << "Name   : " << name << endl;
    cout << "Age    : " << age << endl;
    cout << "Marks  : " << marks << endl;

    return 0;
}

Documentation

Input

Enter your name: Rahul Kumar
Enter your age: 20
Enter your marks: 85.5

 

Output

---- Student Details ----
Name   : Rahul Kumar
Age    : 20
Marks  : 85.5

 

✔ Input using cin
✔ Output using cout
✔ Use of endl
✔ Reading multiple data types
✔ Reading a full line using getline()