//这是一个自己写的关于读写操作的类,思路:先初始化路径,将数组长度写进文件头,然后再写文件主内容。这个类是用于哈夫曼编码,同时也可以用于其他
    //以后只需将这个类实例化,就不用每次都要写那些读写操作,那些操作的代码两天不用就会忘记了~
    
    //制作者:百变星狼_wolf杰
    
    //日期:2012.12.6
    
    #define MAX 256
    
   
    
    template <class T>
    
    class fileOperate
    
    {
    
    
    private:
    
    char path[MAX];//路径
    
    //T typearray;//操作数组
    
    //int len;//数组长度
    
    int temp[2];//缓存数组,储存长度
    
    public:
    
    fileOperate(){}//默认构造函数
    
    fileOperate(const char way[]);//传值函数,传入path
    
    ~fileOperate(){}//默认析构函数
    
    void writeIn(T w[],int len);//写入函数
    
    void readFrom(T w[],int &testLen);//读出函数
    
    };
   
    
    template<class T>
    
    fileOperate<T>::fileOperate(const char way[])
    
    {
    
    
    strcpy(path,way);//初始化文件路径
    
    };
   
    
    template<class T>
    
    void fileOperate<T>::writeIn(T w[],int len)
    
    {
    
    
    FILE *file = fopen(path ,”w”);
    
    temp[0] = len;
    
    fwrite(temp,sizeof(int),1,file);//将长度写进文件头
    
    fwrite(w,sizeof(T),len,file);//写进主要内容
    
    fclose(file);
    
    };
   
    template<class T>
    
    void fileOperate<T>::readFrom(T w[],int &testLen)//读出函数
    
    {
    
    
    FILE *file = fopen(path,”r”);
    
    fread(temp,sizeof(int),1,file);
    
    int len = temp[0];
    
    fread(w,sizeof(T),len,file);//读主体内容
    
    testLen = len;//返回数组长度
    
    fclose(file);
    
    };