← 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
- Input/Output operations in C++ are performed using stream objects that handle data flow
- cin is the standard input stream object used to read data from keyboard
- cout is the standard output stream object used to display data on screen
- Extraction operator (>>) is used with cin to input data from user
- Insertion operator (<<) is used with cout to output data to screen
- getline() function is used to read complete line including spaces
- Header file iostream.h must be included for input/output operations
- Formatting functions like setw(), setprecision() help control output display
- File handling allows programs to store and retrieve data from external files
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
- Students often confuse >> with << operators - remember >> extracts (input), << inserts (output)
- Forgetting to include iostream.h header file before using cin/cout
- Using cin for strings with spaces - use getline() instead of cin >> for complete sentences
- Not understanding that cin stops reading at first space character
- Writing cout >> instead of cout << for output operations
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.