************************* proverb.txt. **********************************
Now Is The Time fOr All GoOd Men to come to the aid of their Family
*************************************************************************
the sample run is as follows:
Sample Run:
The read position is currently at byte 0
Enter an offset from the current position: 4
The character read is I
If you would like to input another offset enter a Y y
The read position is currently at byte 5
Enter an offset from the current position: 2
The character read is T
If you would like to input another offset enter a Y y
The read position is currently at byte 8
[code]
#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;
int main()
{
fstream inFile("proverb.txt", ios::in);
long offset;
char ch;
char more;
do
{
// Fill in the code to write to the screen
// the current read position (with label)
cout << "Enter an offset from the current read position: ";
cin >> offset;
// Fill in the code to move the read position “offset” bytes
// from the CURRENT read position.
// Fill in the code to get one byte of information from the file
// and place it in the variable "ch".
cout << "The character read is " << ch << endl;
cout << "If you would like to input another offset enter a Y"
<< endl;
cin >> more;
// Fill in the code to clear the eof flag.
} while (toupper(more) == 'Y');
inFile.close();
return 0;
}
[/code]
01 |
#include <iostream> |
02 |
03 |
#include <fstream> |
04 |
05 |
#include <cctype> |
06 |
07 |
using namespace std; |
08 |
09 |
int main() |
10 |
11 |
{ |
12 |
13 |
fstream inFile( "proverb.txt" , ios::in); |
Answer #2
#include <iostream> #include <fstream> #include <cctype> using namespace std;
int main() { fstream inFile("proverb.txt", ios::in); long offset; char ch; char more;
do { // Fill in the code to write to the screen cout << "The read position is currently at byte " << inFile.tellg() << endl; // the current read position (with label)
cout << "Enter an offset from the current read position: "; cin >> offset;
//Fill in the code to move the read position “offset” bytes inFile.seekg(offset, ios::cur); //from the CURRENT read position.
//Fill in the code to get one byte of information from the file ch = inFile.get(); //and place it in the variable "ch".
cout << "The character read is " << ch << endl; cout << "If you would like to input another offset enter a Y" << endl; cin >> more;
inFile.clear(); // Fill in the code to clear the eof flag.
} while (toupper(more) == 'Y');
inFile.close();
return 0; } Know the answer?
Add Answer to:
|