Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 704825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:59:06+00:00 2026-05-14T03:59:06+00:00

I’m trying to write a program that takes a large file (of any type)

  • 0

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.

//This file splits are larger into smaller files of a user inputted size.
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include <direct.h> 
#include <stdlib.h>
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 << "Enter a file name: ";
 cin >> filename;   //Recieve target file
 cout << "Enter the number of bites in each smaller file: ";
 cin >> 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 <= (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 << "." << 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() < (size - (size%partsize)))
  {
   filePart.write(reinterpret_cast<char *>(&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<char *>(&bigFile),(size%partsize)); //Write the selected amount to the file
   filePart.close();    //close file
  }
  cout << "File " << CurrentPath << partname << " produced" << endl; //display the progress of the split
 }


 bigFile.close();
 cout << "Split Complete." << endl;
 return 0;
}

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:59:06+00:00Added an answer on May 14, 2026 at 3:59 am

    You are writing to the split file, but not reading from the bigfile. What you are writing it the in-memory structure of the bigfile, not the contents of bigfile. You need to allocate a buffer, read into it from bigfile and write it to the splitfile(s).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.