首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将加密的wstring写入wofstream

将加密的wstring写入wofstream
EN

Stack Overflow用户
提问于 2013-05-27 15:28:44
回答 1查看 239关注 0票数 0

我有一个简单的“加密”函数,它与wstring变量一起工作,我希望使用wofstream将该函数的结果写入文件中。

这是我的密码:

代码语言:javascript
复制
void save_file() {
    wstring text = L"Text to be encrypted. The text is encrypted but not saved";
    wstring enctext = encrypt(text);

    wprintf_s(L"%s\n", 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范围内的字符(或者至少在我看来是这样)。加密文本保存到找到一个未知字符(由显示在控制台中)。我想保存任何字符,我希望它们保存为宽字符(每个字符一个字)。我该怎么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-27 15:58:15

您需要使用fwrite()或相当于写入二进制数据的iostream。fprintf()和eqivalents用于文本(如可读的文本,而不是二进制文本)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16776281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档