|
|||||||
| ||
![]() |
|
|
Seçenekler | Arama | Stil |
![]() c++ Bölünmüs dosyaları birlestiren program | ||||||||||
|
(#1)
|
||||||||||
|
[10]Yeni Üye
![]() Mesaj Sayısı: 656
Açtığı Konu: 196
Level: 23 [ ![]() ![]() ![]() ![]() ]Paylaşım: 55 / 558 Üyelik tarihi: Jul 2007
Kullanıcı No: 105085
Nerden: evden
Tecrübe Puanı: 33
REP Puanı : 100
REP Seviyesi :
![]() ![]() |
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 isimdir.
Kod: #include <iostream> #include <fstream> #include <sstream> #include <iomanip> 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; } |
|||||||||
|
||||||||||
|
|
![]() |
| Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir) | |
| Seçenekler | Arama |
| Stil | |
|
|