如何写入其他人的文件资源。 例如,如果我有构建器,您可以在其中编写电子邮件,用户名。然后,构建器将该信息传输到另一个文件资源中。我怎样才能做到这一点?
我使用End Of File做了类似的事情。当你基本上将信息写入文件结束时。但人们说这种方法不可靠而且不好,我应该使用资源,所以我该怎么做? (C ++)
我的EOF方法如何运作:
存根:
int main(){
int filesize = 104448; // File size . (not file size on disk
Settings data;
long int size = MAX_PATH;
char *filename = new char[size];
GetModuleFileNameA(NULL,filename,size);
ifstream fin(filename,ios::binary); // Gets information that was additionally written into this file
fin.seekg(filesize);
fin.read((char*)&data,sizeof(Settings));
fin.seekg(filesize+sizeof(Settings),ios::end);
size_t len = fin.tellg();
fin.seekg(filesize+sizeof(Settings));
char *bytes = new char[len];
fin.read(bytes,len);
fin.close(); }
助洗剂:
Settings data;
data.bytesLength = file.getBytesLength();
data.owner = m_username;
char * bytes = file.getBytes();
ifstream stub("Stub.exe", ios::binary);
ofstream built("Built.exe",ios::binary);
built << stub.rdbuf();
stub.close();
built.write((char*)&data,sizeof(Settings));
built.write(crc4.Encrypt(file.getBytes(),file.getPassword().c_str()),file.getBytesLength());
built.close();