title: Split a Large File In C++
body: <p>I'm trying to write a program that takes a large file (of any type) and splits it into many smaller "chunks".  I think I have the basic idea down, but for some reason I cannot create a chunk size over 12 kb.  I know there are a few solutions on google, etc. but I am more interested in learning what the origin of this limitation is then actually using the program to split files.  </p>
  
  <pre><code>//This file splits are larger into smaller files of a user inputted size.
  #include&lt;iostream&gt;
  #include&lt;fstream&gt;
  #include&lt;string&gt;
  #include&lt;sstream&gt;
  #include &lt;direct.h&gt; 
  #include &lt;stdlib.h&gt;
  using namespace std;
  
  void GetCurrentPath(char* buffer)
  {
   _getcwd(buffer, _MAX_PATH);
  }
  
  
  int main()
  {
   // use the function to get the path
   char CurrentPath[_MAX_PATH];
   GetCurrentPath(CurrentPath);//Get the current directory (used for displaying output)
  
   fstream bigFile;
   string filename;
   int partsize;
   cout &lt;&lt; "Enter a file name: ";
   cin &gt;&gt; filename;   //Recieve target file
   cout &lt;&lt; "Enter the number of bites in each smaller file: ";
   cin &gt;&gt; partsize;   //Recieve volume size
  
   bigFile.open(filename.c_str(),ios::in | ios::binary);
   bigFile.seekg(0, ios::end);  // position get-ptr 0 bytes from end
   int size = bigFile.tellg();  // get-ptr position is now same as file size
   bigFile.seekg(0, ios::beg);  // position get-ptr 0 bytes from beginning
  
   for (int i = 0; i &lt;= (size / partsize); i++)
   {
    //Build File Name
    string partname = filename;  //The original filename
    string charnum;     //archive number
    stringstream out;    //stringstream object out, used to build the archive name
    out &lt;&lt; "." &lt;&lt; i;
    charnum = out.str();
    partname.append(charnum);  //put the part name together
  
    //Write new file part
    fstream filePart;   
    filePart.open(partname.c_str(),ios::out | ios::binary); //Open new file with the name built above
    //Check if near the end of file
    if (bigFile.tellg() &lt; (size - (size%partsize)))
    {
     filePart.write(reinterpret_cast&lt;char *&gt;(&amp;bigFile),partsize); //Write the selected amount to the file
     filePart.close();    //close file
     bigFile.seekg(partsize, ios::cur); //move pointer to next position to be written
    }
    //Changes the size of the last volume because it is the end of the file
    else 
    {
     filePart.write(reinterpret_cast&lt;char *&gt;(&amp;bigFile),(size%partsize)); //Write the selected amount to the file
     filePart.close();    //close file
    }
    cout &lt;&lt; "File " &lt;&lt; CurrentPath &lt;&lt; partname &lt;&lt; " produced" &lt;&lt; endl; //display the progress of the split
   }
  
  
   bigFile.close();
   cout &lt;&lt; "Split Complete." &lt;&lt; endl;
   return 0;
  }
  </code></pre>
  
  <p>Any ideas?</p>