将加密的wstring写入wofstream
Write encrypted wstring to wofstream
我有一个简单的"加密"函数,它与wstring
变量一起工作,我想将这个函数的结果写入一个文件,使用wofstream
。
这是我的代码:
void save_file() {
wstring text = L"Text to be encrypted. The text is encrypted but not saved";
wstring enctext = encrypt(text);
wprintf_s(L"%sn", enctext);
wofstream output_stream;
output_stream.open(L"myfile.enc");
output_stream<< enctext ;
output_stream.close();
}
wstring encrypt(wstring decrypted) {
wstring encrypted;
for (unsigned int i=0; i<decrypted.length(); i++) {
encrypted += wchar_t(int(decrypted[i]) + 128);
}
return encrypted;
}
所以,这个问题是…代码是,虽然wprintf_s
函数输出整个加密文本,在书面文件中,我只看到ASCII范围内的字符(或者至少是对我来说)。加密文本被保存,直到找到一个未知字符(由显示?)。我想保存任何字符,我希望他们保存为宽字符(1字每一个)。我该怎么做呢?
您需要使用fwrite()
或等效的iostream来写入二进制数据。fprintf()
及其等价值用于文本(即可读文本,而不是二进制文本)。
相关文章:
- 写入向量<向量<bool>>
- 如何将内容数组写入文本文件?
- 写入位置0x0000000C时发生访问冲突
- 使用ios:ate写入到流会覆盖现有文件
- 独立读取-修改-写入顺序
- 为什么在某些情况下不写入此文件?
- 用C++将哈希表写入文件并从文件中恢复
- std::当在256字节边界上写入整数时,流的奇怪行为
- 为什么指针不写入类的地址?
- 如何打开并写入一个名称取自C++中字符串的文件
- 如何在C++中从文件中读取/写入多个对象
- 链表中写入访问冲突的未知原因
- 着色器纹理值与创建纹理时写入的值不同
- MESI协议和std::atomic-它是否确保所有写入立即对其他线程可见?
- 在C++中一次将矢量值写入多个文件
- 当字段可以为null时,如何使用C++接口在Avro中写入数据
- 写入文件会产生一个空文件或根本没有文件
- std::带有自定义缓冲区的 iostream 不允许我写入
- 无法使用 wofstream 将汉字写入文本文件
- 将加密的wstring写入wofstream