will any body plz tell me about random access file.i need to know about write random data on random access file.
this data can be of any txt file?kindle mention some initial coding.reply sooooon plzzzzzzz

will any body plz tell me about random access file.i need to know about write random data on random access file.
this data can be of any txt file?kindle mention some initial coding.reply sooooon plzzzzzzz

I think this is what you mean, please feel free to correct me

Reading Files

///Read a text file and output contets to console.
#include <iostream>
#include <fstream>
#include <stdlib.h>//Allows access to 'System' 'FuNti0N's'
#include <cstdlib>//Allows access to special 'FuNti0N's'

using namespace std;

int main()

{
 
   char The_FileName[50];//Declares 'The-File_Name' as data type 'char' 
   ifstream ReadFile;//
   cin.getline(The_FileName, 50);//
   ReadFile.open(The_FileName);//

   if (!ReadFile.is_open())//Check if file is allready open,
   {
      return 0;
   }

   char Contents_Of_Text_File[100];
   ReadFile >> Contents_Of_Text_File;

   while(ReadFile.good())
   {

      cout << Contents_Of_Text_File << " ";
      ReadFile >> Contents_Of_Text_File;

   }

system("PAUSE");
return 0;


}

Writing to files

///Will create a new Text Document, If no such file exists.
#include <iostream>
#include <fstream>//File Stream Header, allows access to required funtions.
#include <stdlib.h>
#include <string>
using namespace std;

int main()

{
   string Input;

  
   getline(cin, Input);

   ofstream MyNewFile;//Declare Name of file(Variable)
   MyNewFile.open("MyNewFile.txt");//Create New file, or idit existing file.
   MyNewFile << Input;//Write to file, note will overwrite.
   MyNewFile.close();//Close file; Stop Memory Leaks.

   /*Or You Could do.....
   ofstream MyNewFile("MyNewFile.txt", ios_base::app);//This will only ammend the file,
   will only write to the end of file.
   */

   system("PAUSE");//Pause console.

return 0;


}

Again i apologise if i have misunderstood....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.