Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
35 views24 pages

Unformatted Io

The document discusses unformatted and formatted I/O in C++ using manipulators, explaining their roles in controlling data display and input/output operations. It differentiates between unformatted I/O, which handles raw data, and formatted I/O, which uses manipulators for cleaner output. The conclusion emphasizes the benefits of combining both approaches in Object-Oriented Programming for improved readability and control.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views24 pages

Unformatted Io

The document discusses unformatted and formatted I/O in C++ using manipulators, explaining their roles in controlling data display and input/output operations. It differentiates between unformatted I/O, which handles raw data, and formatted I/O, which uses manipulators for cleaner output. The conclusion emphasizes the benefits of combining both approaches in Object-Oriented Programming for improved readability and control.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

OOPS

PRESENTATION
Topic:Unformatted and Formatted I/O
using Manipulators in C++
07301032023 : VANIA GOEL
07401032023 : VANSHIKA
07501032023 : VANSHIKA JAIN
07601032023 : YASHASVI
07701032023 : YOGITA
Introduction to I/O in C++

In C++, Input/Output (I/O) operations allow a program


to interact with the user or other systems.
There are two main types of I/O:
Unformatted I/O – Basic, raw data transfer without
control over output format.
Formatted I/O – Customizable, cleaner, and more
readable output using manipulators.
Manipulators are special functions that help format
the output (like controlling width, precision,
alignment).
Unformatted I/o
Unformatted I/O refers to input and output operations that deal with raw data
rather than interpreting or formatting it. Unlike formatted I/O (cin and cout
with manipulators like setw, setprecision, etc.), unformatted I/O functions
process data at the character level or as raw blocks of bytes.

Why Use Unformatted I/O?


To handle complete lines, including whitespaces.
To deal with binary data or exact byte-sized data.
To process raw input/output without formatting logic.
Unformatted Input Functions
2. cin.getline()
1. cin.get()
Reads a line of text including spaces, until newlin
Reads one character at a time, including
\n or a specified limit.
whitespace.

3. cin.read()
Used to read binary or raw data into a character array.
Unformatted Output Functions
1. cout.put() 2. cout.write()
Writes a single character to the Writes a block of characters (including null or special
output. characters).
Manipulators
What Are Manipulators?
Manipulators are operators that are used to format the data display.
It is mainly used for make-up the program.
Manipulators functions are special stream function that changes certain
characteristics of the input and output.
To carry out the operations of the manipulators functions in user program,
the header file input and output manipulator <iomanip> must be included.
Manipulators are the functions specially designed to be used in conjunction
with insertion (<<) and extraction (>>) operator on stream object.
e.g.: cout << boolalpha;
Manipulators are used to change formatting parameters on streams and to
insert or extract certain special characters.
Types of Manipulators
1.Formatting (Output) Manipulator Description Example
Manipulators
Sets field width to n cout << setw(10)
setw(n)
These control how data is characters << 123;
displayed using cout.
Fills empty width cout <<
Found in the <iomanip> setfill(c) space with character setfill('*') <<
header. c setw(5) << 42;

Sets the number of cout <<


setprecision(n) digits printed after setprecision(2)
decimal << 3.1415;

Forces fixed-point cout << fixed <<


fixed notation for floating setprecision(2)
numbers << 3.14;
Displays floating-point in
scientific cout << scientific << 123.45;
scientific notation

Aligns output to left or


left / right cout << left << setw(10) << "Hi";
right within setw()

Forces decimal point to


showpoint cout << showpoint << 25.0;
be shown

Hides unnecessary
noshowpoint cout << noshowpoint << 25.0;
decimal point

Displays + sign for


showpos cout << showpos << 15;
positive numbers
2.Base Manipulators
Used for displaying numbers in different numeral systems.

Manipulator Description Example

Decimal base
dec cout << dec << 255;
(default)

Hexadecimal base
hex cout << hex << 255;
(0–F)

oct Octal base (0–7) cout << oct << 255;

Sets base to 8, 10, or


setbase(n) cout << setbase(16) << 255;
16
3. Unformatted Input/Output Manipulators
These control low-level stream behavior and whitespace handling.

Manipulator Description Example

ws Skips leading whitespace in input cin >> ws >> ch;

cout << "Done" <<


flush Flushes the output buffer immediately
flush;

cout << "Text" <<


ends Inserts a null character ('\0') in the stream
ends;
Manipulators in
OOPS
Why Use Manipulators in OOP?
When working with classes and objects in C++, manipulators
help:
Format object data neatly during display
Control spacing, alignment, and precision
Clean input (like removing extra whitespaces)
Make class-based output more user-friendly and readable
Combination of manipulators and
i/o
In Object-Oriented Programming (OOP) in C++, unformatted
I/O using manipulators typically refers to using
manipulators to control the way input/output happens
without relying on specific formats or structures. This
contrasts with formatted I/O like using printf or
std::setw, where you're specifying exact widths, precision,
etc.
However, manipulators are mostly used for formatted I/O,
but some are also useful in the context of unformatted I/O
when you want to tweak the stream's behavior while still
keeping the output simple or free-form.
Example
Manipulators Used Here
Manipulator Description
setw(n) Sets field width to n. Works once per output item.
left / right Aligns output to left or right.
endl Ends the line and flushes the output buffer.

Even though we're using setw and left, the I/O is still relatively
unformatted, especially on the input side (getline, cin). We're not
forcing output into a strict table or format beyond spacing.
If you want more raw unformatted I/O, you could use:
cin.get() or cin.read() – for raw input
cout.put() or cout.write() – for raw output
Example
Example

O/P
Example
Example

O/P
Real-Life Use Cases
Billing Systems – Align product names, quantities, prices,
and totals.
Real-Life Use Cases
Bank Statements – Cleanly formatted account numbers,
amounts, and dates.
Real-Life Use Cases
Data Reports – Control number precision and layout in
scientific or business reports.
System Output Tools – Format CPU/memory usage in readable
columns.
Student Marksheet Generator – Align names, marks, and
grades for clarity.
Real-Life Use Cases
System Logs (Internal log files) and Error messages
(Crash/error dump files) are often written using
unformatted I/O for speed and consistency.
Not for end-user consumption — only readable through tools
or by developers.

Formatted

Unformatted
Conclusion
Feature Unformatted I/O Manipulators

Raw character
Purpose Modify stream behavior
input/output

Example cin.get(), cout.put() setw(), left, right

Full control over how Makes raw I/O more


Benefit
data flows readable

Inside class getData() Used to enhance method


OOP Use
and display() output
Conclusion
Unformatted I/O in C++, especially when used within Object-Oriented Programming
(OOP), gives you fine-grained control over how input and output are handled—
character by character, line by line—without imposing strict formatting rules. This
is particularly useful when working with raw data, handling special characters, or
building custom input methods inside classes.

By combining this with manipulators like setw, left, or endl, you can enhance the
readability and structure of your output, even when you're not formatting it in a
traditional sense. This hybrid approach gives the best of both worlds: flexibility
and clarity, making your code cleaner, more user-friendly, and easier to manage in
larger OOP-based programs.
In short:
🔹 Unformatted I/O gives you control.
🔹 Manipulators give you clarity.
🔹 Together in OOP, they help build clean, efficient console applications.
THANK
YOU

You might also like