我现在正在为一个基本的虚拟文件系统存档(没有压缩)编写一个提取器.
我的提取器在将文件写入不存在的目录时遇到问题.
提取功能:
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;
}
Run Code Online (Sandbox Code Playgroud)
ifs是vfs根文件,offset是文件启动时的值,length是文件长度,path是文件中保存偏移len等的值.
例如,path是data/char/actormotion.txt.
谢谢.
我有一个问题.
我在ASIO中开发服务器,数据包是尖头char.
当我创建新的char(例如char * buffer = new char[128];)时,我必须手动将其清理为空值.
通过:
for(int i =0;i<128;i++)
{
buffer[i] = 0x00;
}
Run Code Online (Sandbox Code Playgroud)
我做错了,那个字母不清楚?
将数组int放入char数组的最佳方法(性能)是什么?这是我目前的代码:
data[0] = length & 0xff;
data[1] = (length >> 8) & 0xff;
data[2] = (length >> 16) & 0xff;
data[3] = (length >> 24) & 0xff;
Run Code Online (Sandbox Code Playgroud)
data是一个char数组(共享ptr),length是int.
我有一个问题.
是否有库或类似于组合int和字符串到字节数组?
喜欢 :
byte temparray[] = new byte[10];
int a = 10;
int b = 10;
temparray << new String("12") << a << b;
Run Code Online (Sandbox Code Playgroud)
谢谢.
byte[] buffer = new byte[649];
byte[] charname = this.getName().getBytes();
System.arraycopy(charname, 0 , buffer, 0, charname.length);
for(int i=0;i<16;i++) //mystery crs 16 zeros
{
buffer[i+17] = (byte)0x30;
}
buffer[34] = this.faction;
if(this.characterClass == 2)
{
buffer[40] = 2;
} else
{
buffer[40] = 1;
}
System.arraycopy(BitTools.shortToByteArray(face), 0, buffer, 42, 2);
buffer[44] = 1;
buffer[48] = …Run Code Online (Sandbox Code Playgroud)