title: How to multithread file processing in C++?
body: <p>I'm working on one problem where I need to process 24 files (each size = 3 GB) and write the output into multiple files (24). Each file takes around 1 hour to process. Is it possible to write data into multiple files concurrently using multi-threading with below code?</p>
  
  <pre><code> int _tmain(int argc, _TCHAR* argv[])
      {
          std::string path;
          cout &lt;&lt; "Enter the folder of the logs:  " &lt;&lt; endl; 
          cin &gt;&gt; path;
  
          WIN32_FIND_DATA FileInformation;       // File information  
          memset(&amp;FileInformation, 0, sizeof(WIN32_FIND_DATA));         
          std::string strExt =  "\\*.txt";
          std::string strEscape = "\\";
          std::string strPattern = path + strExt;             
          HANDLE hFile = ::FindFirstFile(strPattern.c_str(), &amp;FileInformation);  
  
          while(hFile != INVALID_HANDLE_VALUE)     
          {
              int offset;
              std::ifstream Myfile;
              std::string strFileName = FileInformation.cFileName;
              std:: string fullPath = path + strEscape + strFileName;
              std::string outputFile = path + strEscape + strFileName.substr(0, strFileName.length()-3) + "processed"+".txt";
              std::ofstream ofs(outputFile, std::ofstream::out);
  
              Myfile.open (fullPath);
              std::string line;
  
              if(Myfile.is_open())
              {
                  while(!Myfile.eof())
                  {
                  -------Processing--------
                  }
  
                  Myfile.close();
  
              }
              else
                  cout&lt;&lt;"Cannot open file."&lt;&lt;endl;
  
              if(FindNextFile(hFile, &amp;FileInformation) == FALSE)
                  break;
          }      
          // Close handle  
          ::FindClose(hFile);        
          return 0;
  
      }
  </code></pre>