OOP 313304 Practical No.23: Write programs to read and write from/to file using Constructor, Open()
Files store the output of a program and help to perform various operations on it. Files help store these data permanently on a storage device.
Exercise:
1. Write output for the following code
Answer:
The content of a text file testout.txt is set with the data:
Welcome to javaTpoint.
C++ Tutorial.
2.Write a program in C++ in which open a file read and write mode ad display
the content onAnswer:
3. output screen using function open()
Answer:
4.Write a program in C++ in which open a file read and write mode ad display the content on output screen using constructor.
Answer:
Result
The program writes specific content to a file named
testout.txt
and successfully creates or overwrites the file if it opens correctly.Practical Related Questions
1. Which operator is used to insert the data into file?
a) >>
b) <<
c) <
d) none of the mentioned
Answer:
b) <<
2. Which function is used to position back from the end of file object?
a) seekg ()
b) seekp()
c) both seekg() & seekp()
d) none of the mentioned
Answer:
c) both seekg() & seekp()
3. Write a C++ program to Read and Display File's Content.
Answer:
4. Write a C++ program to List Files in Current Directory.
Answer:
5.What is the return type open() method?
a)int
b)char
c)bool
d) float
Answer:
c) bool
6. Complete the following table:
Answer:
We successfully completed OOP 313304 Practical No.23 and Write programs to read and write from/to file using Constructor, Open().