【发布时间】:2013-09-11 23:49:23
【问题描述】:
我现在正在为基本的虚拟文件系统存档(不压缩)编写一个提取器。
我的提取器在将文件写入不存在的目录时遇到问题。
提取函数:
void extract(ifstream * ifs, unsigned int offset, unsigned int length, std::string path)
{
char * file = new char[length];
ifs->seekg(offset);
ifs->read(file, length);
ofstream ofs(path.c_str(), ios::out|ios::binary);
ofs.write(file, length);
ofs.close();
cout << patch << ", " << length << endl;
system("pause");
delete [] file;
}
ifs 是 vfs 根文件,offset 是文件启动时的值,length 是文件长度,path 是文件中保存偏移量 len 等的值。
例如路径是 data/char/actormotion.txt。
谢谢。
【问题讨论】:
-
std::ofstream是不可能的,它只用于写入文件。boost中可能有一个很好的包装器,可以在任意平台上创建目录。 -
@WhozCraig 这会很困难,因为这个档案在不同的目录中有 20 000 个文件。
标签: c++ filestream