Hi, i am trying to make a general compression algorithm in c++ but i haven't really gotten the i/o part of this right yet. What i want to do somewhere along the line is to have my program parse say 10 or so characters at a time from a binary file which will then be processed with my compression algorithm and then outputted to another file. How would i go about correctly PARSING or just storing 10 bytes at a time to a certain string? Any help is appreciated. Thanks.

Code so far (this stores the entire file to a string but i don't want someone to go about compressing a 2GB file and not have enough memory to compress the file.

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main (void)
{
    ifstream infile("c:\\myfile.exe",ios::in|ios::binary);
    string contents((istreambuf_iterator<char>(infile)),istreambuf_iterator<char>());
    cout<<endl<<"contents stored to memory."<<endl;
    system("pause");
    return 0;
}

Recommended Answers

All 2 Replies

thanks!!!! this actually worked!!

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.