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";
          string searchWord = argv[2];
          string compareStr;
          int searchSize = searchWord.size();
               readFile.getline(oneLine, MAXLINE);
               compareStr = "";
               for (int i = 0; i < searchSize; ++i)
                    compareStr += oneLine[i];
               if (searchWord.compare(compareStr) == 0)
                    writeFile << oneLine << "\n";
     return 0;                

Thanks in advance! :)

-Miss VaVaZoom

6 Years
Discussion Span
Last Post by Ancient Dragon

Read this

If you use MS-Windows you can use your 32-bit compiler to read the file if you use win32 api file/io functions instead of std::fstream. AFAIK there are no 64-bit implements of fstream for 32-bit compilers.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.