【发布时间】:2014-10-30 14:25:43
【问题描述】:
我使用wofstream 来合并文件并写入 wstring 和整数(直接来自内存)。我的问题(目前)是假设我有int32,其中包含号码7。在内存中它需要 4 个字节,但是当我将它写入流并使用十六进制查看器检查时,我只看到了这个 -- 7(单字节)。
当然这对我没有用,因为我必须阅读它并且可靠地阅读它。
那么如何让stream根据type来写数据--所以2 bytes类型要2 bytes,4 bytes-- 4 bytes,以此类推?
记录一下我的合并功能:
for (const std::wstring &fn : files)
{
std::wifstream is_src(dst_dir+fn, std::ios_base::binary);
os_dest << is_src.rdbuf();
os_dest << fn;
os_dest << static_cast<__int32>(fn.size());
}
os_dest << static_cast<__int32>(files.size());
我添加了强制转换以 100% 确定有 4 个字节,仅此而已。
【问题讨论】: