Object Oriented Programming - C++ : Chapter 6: IO Systems and File IO : Anna University Part A Two Marks Important Questions and Answers
Object Oriented Programming – C++
Chapter 6: IO Systems and File IO
Two Marks
Questions with Answers
1. What
is stream?
Answer: Stream
is a channel on which data flow from sender to receiver. Data can be sent out
from the program in an output stream or received into the program in an input
stream. A stream is connected to a physical device by the C++ input output
system. Examples: The cin is a standard input stream and cout is a standard
output stream.
2. Enlist
the libraries used in handling the stream operations.
Answer:Following
are the standard header files used for handling the stream operations
a.
iostream.h
b.
iomanip.h
c.
strstream.h
d.
fstream.h
3. What
is formatted I/O ?
Answer:
Each stream is associated with a set of format flags that control the way
information is formatted. The ios class declares the values that are used to
set or clear the format flags. Some format flags are
Flags:
Meaning
skipws:
If this flag is set then leading white spaces are discarded(skipped). On
clearing this flag the leading white spaces are not discarded.
left:
On setting this flag the output becomes left justified.
right:
On setting this flag the output becomes right justified.
scientific:
On set it shows exponential format on floating point numbers
fixed:
On set it shows fixed format on floating point numbers.
uppercase:
On setting this flag upper case A‒F are used for hex values and E for
scientific values.
4. How
can you create a file in the append mode?
Answer:
The ios::app mode is used for opening the file in append mode. The code for
this is
ofstream
fp; //creating a file object for writing to the file.
fp.open("output.dat",ios::app)
5. What
is file mode ? List any four file modes.
Answer:
File mode is a specification which denotes the manner by which the file is to
be opened. Various file modes are
Ios::in:
Open for input operation.
Ios::out:
Open for output operation.
Ios::binary:
Open for binary operations.
6. Give
the purpose of gets and puts function.
Answer:
The gets(char *str) is used for reading the string. The puts(char *str) is for
displaying the string as an output. In other words gets is for reading the
string and the puts is for writing the string.
7. List
down the functions of manipulators.
Answer:
Following table shows some commonly used functions of manipulators
Function : Meaning
showbase ‒ Shows
numerical base prefix
showpoint ‒ Shows
decimal point
uppercase ‒ Converts
to upper case letters
skipw ‒
Skips whitespaces
endl ‒ Inserts newline.
setw ‒ Sets the field width
8. What
are manipulators? Give any two examples.
Answer:
Manipulators are the operators in C++ that are used for formatting the output.
Various commonly used manipulators are setw, endl and setfill.
The
setw is used to set the minimum field width. For example ‒ setw(30) will set
the right justified numbers
The
endl is similar to a newline character.
9. Give
the meaning of the flag ios::out.
Answer:
The flag ios::out is used for opening a file for output operation.
10. Explain
the seek operation used in file.
Answer:
The seek operation is used to reach to any desired position inside the file.
There are two commonly used functions associated with seek‒
a.
seekg ‒ Means get pointer of specific location for reading of the record.
b.
seekp ‒ Means get pointer of specific location for writing of the record.
The
syntax for the seekg and seekp operations is
seekg(offset,reference‒position);
seekp(offset,reference‒position);
11. Explain
the tell function.
Answer:
The tell function is used to tell the current position in the file.
For
example:
seqfile.tellg()
‒ returns the current position of get pointer(for reading the record)
seqfile.tellp()
returns the current position of put pointer(for writing the record)
Object Oriented Programming: Chapter 6: IO Systems and File IO : Tag: Oops, Computer Programming : C++ Object Oriented Programming - IO Systems and File IO: Two Marks Important Questions and Answers
Object Oriented Programming (OOPs)
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Object Oriented Programming (OOPs)
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Re-Engineering for Innovation
ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Object Oriented Programming (OOPs) - Laboratory
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation