我现在正在为一个基本的虚拟文件系统存档编写提取器(不带压缩)。
当我的提取器将文件写入一个不存在的目录时,就会遇到问题。
提取函数:
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
是保存偏移量、长度等文件中的值。
例如,路径为 data/char/actormotion.txt。
谢谢。
std::ofstream
是不可能的,它只用于写文件。在boost
中可能有一个很好的封装来创建任意平台上的目录。 - stefan