Explain file pointers and operations. Write a C++ program which demonstrates the use of put( ) — get( ) and read( ) — write( ).
File pointers in C++ are references or indicators used to access and manipulate files. They keep track of the current position within a file, allowing operations like reading, writing, or moving within the file. There are standard file pointers in C++, such as `fstream` for file I/O operations.
The `put()` and `get()` functions are used for single character I/O operations. `put()` is used to write a single character to a file, while `get()` reads a single character from a file. On the other hand, `read()` and `write()` are used for block I/O operations. `write()` is used to write a specified number of bytes from a buffer to a file, and `read()` reads a specified number of bytes from a file to a buffer.
Here's a C++ program that demonstrates the use of `put()` and `get()` for character-based I/O, and `read()` and `write()` for block-based I/O:
```cpp
#include <iostream>
#include <fstream>
using namespace std;
int main() {
// Writing to a file using put()
ofstream outFile("output.txt", ios::out | ios::binary); // Opening file in binary mode
if (!outFile) {
__________ __________ ____ _______ ________ _______ _________ _________.
________ _______ _____ ________ _________ _____ _______ ______ ____ _______ ____.
_________ _________ ______ ______ ______ _____ ______ __________ ______.
_______ _________ ______ _______ _______ __________ ______ _____ _________ __________.
_________ ___ _____ __________ _____ _____.
_________ _________ ____ ____ ___ _______ __________ _______ ________ _______.
_______ ____ _______ ____ ____ ________ _______ _______ _____ ____.
__________ __________ _______ ___ _______ ______ ____ ________ _______.
________ __________ ___ _________ _________ ___ ______.
_______ ________ ____ _______ _____ _______ __________ __________ ______ ____ ____ ____.
_________ __________ _________ ______ ________ ___.
_________ ________ ___ ______ ____ _________ __________ _____ _____ ______ __________.
__________ ___ __________ ____ _______ _______ ________.
______ ____ ___ ____ ______ ___ ___.
__________ _____ ____ ________ ________.
_________ _____ _________ ___ ____ ____ ____ _______.
_________ _________ ____ __________ _______.
_____ ________ ____ __________ _________ ___ __________ _______.
_______ ____ ________ __________ ________ _____ ________.
_________ _____ _______ ________ ___.
________ ______ ______ ______ _________ __________.
_________ ____ ____ __________ __________.
___ ___ _______ __________ _____ ______ _________ ______ ____ _____ _________ ______.
________ _________ _________ _____ _______ ______.
____ __________ ___ __________ _______.
________ _____ ____ ______ ___ _____ _____.
_____ _______ ________ _____ ________ __________.
________ _______ ____ _________ _____ __________ _________ ________ ______ ____.
__________ __________ _____ _________ ________ ________.
_____ _______ ______ _________ _____.
_______ _____ ______ ________ __________ ______ _________ _____ ________.
____ ________ _________ _______ ___ ______.
________ __________ ______ ____ _______ ___ ________.
_______ _________ ___ __________ ____ _____ ________.
_____ ___ ____ ____ ________ _______ _______ ________ __________.
_____ ____ ____ ________ _______ ______.
____ _________ ___ __________ ________ ______ __________ _________.
__________ ___ ____ _______ _______ __________ ___.
__________ __________ _____ ____ __________ _________.
_________ __________ ____ ____ ________ ___ ________ ___ ___ _____ ______.
______ _________ ____ _____ ______ _____.
________ ______ ____ ____ ____ ______ _________ __________.
____ __________ _______ ________ _________ ______ __________ ___ _____ ________ ____ ___.
_________ ____ _____ __________ ________ _______ _________ ________ _______ __________ __________.
________ ___ __________ ___ _______ _____ ________ _______.
___ ________ ____ ___ _______ ______ _________ __________.
________ _________ _____ _________ ________ ___.
_________ ____ _____ _______ _______ _______ _________ ______ ______ _______ ________ __________.
_________ ___ ____ ________ _____ _______ _________ __________ ______ _________ _________ ___.
___ ___ ___ ____ ________ ___ ____ ____ _________ _________ ______.
________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required