vavazoom 0 Light Poster

I am trying to extract data from a 1.5 GB text file.
The problem occurs when the program tries to open the large text file.
It works perfectly on smaller files. Does anyone know how to successfully open a file of this size? Or, is there a better way to extract the data?

The objective is to go line by line, searching for a specific value in the first column of the data text file...and extracting the entire line...writing it to a new file.

Here is what I have:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int MAXLINE = 256;

int main (int argc, char *argv[])
{
     ifstream readFile (argv[1], ifstream::in);
     ofstream writeFile ("extractedData.txt", ofstream::out);
     char oneLine[MAXLINE];
     
     //Checks to see if the file opened successfully
     if ( !readFile.is_open() )
     {
          cout << "Could not open file\n";
     }
     else
     {
          string searchWord = argv[2];
          string compareStr;
          int searchSize = searchWord.size();
          while(!readFile.eof())
          {
               readFile.getline(oneLine, MAXLINE);
               compareStr = "";
               for (int i = 0; i < searchSize; ++i)
               {
                    compareStr += oneLine[i];
               }
               if (searchWord.compare(compareStr) == 0)
               {
                    writeFile << oneLine << "\n";
               }  
          }
     }
     readFile.close();
     writeFile.close();
     return 0;                
}

Thanks in advance! :)

-Miss VaVaZoom

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.