Bölünmüş dosyayı yeniden birleştiren program
Jul 24,2007 00:00 by mustaYfa

Aşağıdaki program "bol" programı ile bolunmus dosyaları yeniden birleştiriyor. Program komut satırından aşağıdaki gibi çalıştırılmalı: bir dosya_ismi dosya ismi parçaların birleştirilmesiyle elde edilecek olan dosyaya verilen is

imdir

#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char **argv)
{
    string destname;
    
    if (argc != 2) {
        cout << "hedef dosya ismi " << endl;
        cin >> destname;
    }
    else
        destname = argv[1];

    ofstream ofile(destname.c_str(), ios_base::binary);
    
    if (!ofile) {
        cerr << "cannot create " << destname.c_str() << endl;
        return 1;
    }
    int file_counter = 0;    
    int byte_counter = 0;
    ostringstream sourcename;
    ifstream infile;
    
    for (;;) {
        sourcename << "part" << setfill('0') << setw(4) << file_counter + 1 << ".nnn";
        infile.open(sourcename.str().c_str(), ios_base::binary);
        if (!infile)
            break;
        ++file_counter;
        
        char ch;
        while (infile.get(ch)) {
            ofile.put(ch);
            byte_counter++;
        }
        infile.close();
        infile.clear();
        sourcename.str("");
    }
    
    cout << "total  " << file_counter << " files united as " << destname << " with the size of " << byte_counter
    << " bytes" << endl;
    
    for (int k = 1; k <= file_counter; ++k) {
        sourcename.str("");
        sourcename << "part" << setfill('0') << setw(4) << k << ".nnn";
        if (remove(sourcename.str().c_str()))
            cout << "cannot remove " << sourcename.str() << endl;
    }
    
    system("pause");
    
    return 0;
}