Question: Ramdon Acess Files c++ Write a program which enables to write data to an output file then gives the user options on reading the data
Ramdon Acess Files c++ Write a program which enables to write data to an output file then gives the user options on reading the data from the file. used this menu 1) reading from the beggining 2) read from any specific location to the end 3) read from any specific location to any specifi location 4) read data in reverse order from any specific location to any specific location.
is what i have so far , please i just need someone to help me with step 2 , 3 and 4 , this is c++
// Xavier Tenezaca // computer science 265 // Date: 1/26/18 // Project input and outputz
#include
#include
#include
#include
#include
#include
using namespace std;
int main ()
{
int size=5;
string dataline1[5];
char filename[]= "D:Documents\\Thefile.txt";
fstream OutFile;
OutFile.open(filename);
if(OutFile.fail()) // check for successfully open , can be written as if(! OutFile) exit;
{
cout << "file named can not be found ";
exit(1); // needs the stdlib
}
int i=0;
for (int i=0; i { cout << "enter data for line "; cin >> dataline1[i] ; } int num=0; for ( int num=0; num { OutFile << dataline1[i] << endl; } OutFile.close(); int selection; // Menu cout<<" Output Options"; cout<<" ========"; cout<<" 1 - Read from Beggining "; cout<<" 2 - Read from a specific place to end"; cout<<" 3 - Read from any specific place to another specific place"; cout<<" 5 - read in reverse from any specific place to another"; cout<<" 4 - Exit"; cout<<" Enter selection: "; cin>>selection; switch(selection) { case 1 : { ifstream fin; fin.open("D:Documents\\Thefile.txt", ios::in); char my_character ; int number_of_lines = 0; while (!fin.eof() ) { fin.get(my_character); cout << my_character; } } break; }}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
