问题描述
我目前正在开发一个项目,从文件中读取二进制数据,然后再将其写回。到目前为止,读取工作得很好,但是当我尝试将存储在字符串中的二进制数据写入文件时,它会将二进制文件作为文本写入。我认为这与打开方式有关。 这是我的代码:
void WriteBinary(const string& path,const string& binary)
{
ofstream file;
file.open(path);
std::string copy = binary;
while (copy.size() >= 8)
{
//Write byte to file
file.write(binary.substr(0,8).c_str(),8);
copy.replace(0,8,"");
}
file.close();
}
在上面的函数中,binary
参数看起来像这样:0100100001100101011011000110110001101111
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)