Pakistani.education

← Sindh Board notes

AI draft — not yet reviewed by a teacher. Check with your teacher.

Computer Science · Class 10 · Chapter 10: Input/Output Handling in C++

8 min

Key points

Definitions

Stream
A stream is a sequence of bytes that flows from source to destination. It provides a uniform interface for input and output operations.
Input Stream
An input stream is a stream that brings data into the program from an external source like keyboard or file.
Output Stream
An output stream is a stream that sends data from the program to an external destination like screen or file.
Extraction Operator
The extraction operator (>>) extracts or reads data from the input stream and stores it in variables.
Insertion Operator
The insertion operator (<<) inserts or writes data from variables to the output stream.

Worked example

Write a C++ program that takes two numbers as input and displays their sum. Also explain the header file used. (6 marks)

#include<iostream> using namespace std; int main() { int a, b, sum; cout<<"Enter two numbers: "; cin>>a>>b; sum = a + b; cout<<"Sum is: "<<sum; return 0; } The iostream header file contains definitions for input/output stream objects like cin and cout.

Common mistakes

Quick recap

Input/output in C++ uses iostream header file. cin is input stream object for taking data from keyboard. cout is output stream object for displaying data on screen. Use >> operator with cin and << operator with cout.

Generated by AI from Sindh Textbook Board material; review state: ai_unreviewed. MCQs, past-paper references and examiner notes are held back until a teacher has checked them.