954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do i read a huge file of data from a text file in c++?

Hi Guys,

I want to read a huge file which contains address bits, data bits and instruction bits. Please let me know how to do this.

Cheers,
Bond

doublebond
Newbie Poster
7 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 
#include <fstream>
 #include <iostream>
 #include <cstdlib>
 using namespace std;
 using std::ifstream;
 using std::ofstream;
 using std::cout;
 int main( )
 {
         ifstream fin;
         ofstream fout;
         fin.open("trace.txt");

         if (fin.fail( ))
         {
                 cout << "Input file opening failed.\n";
                 exit(1);
         }

         fout.open("stats.txt");

         if (fout.fail( ))
        {
         cout << "Output file opening failed.\n";
         exit(1);
        }
int next;
         int n = 1;

         fin.get(next);
         fout << n << " ";
         while (! fin.eof( ))
         {
                fout << next;

         if (next == 1)
         {
                 n++;
                 fout << n << ' ';
         }

         fin.get(next);
 }

 fin.close( );
 fout.close( );
 return 0;
 }
doublebond
Newbie Poster
7 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

How huge is huge? What problem are you having?

Tom Gunn
Master Poster
733 posts since Jun 2009
Reputation Points: 1,446
Solved Threads: 135
 
How huge is huge? What problem are you having?

The thing is that--- I am trying take a trace of the traffic flowing in the bus which connects the memory components, i am not yet done with pulling the trace out. This trace contains address bits, data bits and instruction bits. The problem with me is like, i want read the trace.txt to analyze it. This trace.txt is expected to be very huge as we running large application programs on the machine.

doublebond
Newbie Poster
7 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You