文件存储第一步(有待修改)

// reading an entire binary file
#include <iostream>
#include <fstream>
#include <bitset>
#include<vector>
using namespace std;

int main () {
    streampos size;
    char * memblock;
    char * memblock2;
    bitset<8> bbb =8;
    vector<int> vecint;

    ifstream file ("3.rar", ios::in|ios::binary|ios::ate);
    ofstream  ofile("4.rar", ios::out|ios::binary|ios::ate);
    if (file.is_open())
    {
        size = file.tellg();
        memblock = new char [size];
        memblock2 = new char [size];
        file.seekg (0, ios::beg);
        file.read (memblock, size);
        for (int j=0;j<size;j++)
        {
            bbb =memblock[j];
            vecint.push_back(bbb.to_ulong());
        }
        for (int j=0;j<size;j++)
        {
            memblock2[j] = vecint[j];
        }

        ofile.write(memblock2, size);
        file.close();

        cout << "the entire file content is in memory";

        delete[] memblock;
        delete[] memblock2;
    }
    else cout << "Unable to open file";
    return 0;
}
View Code

 

posted @ 2015-08-22 18:00  lwn6  阅读(138)  评论(0编辑  收藏  举报
什么是幸福?天天在做自己想做的事情,家人、同事、朋友、客户、网友都和和睦睦,身体健康、钱包鼓鼓、女朋友天天开心、生活无忧无虑就是最大的幸福