每次都在以前代码中找这段代码,现在放上来,方便查找。
#include <boost/program_options/detail/convert.hpp>
#include <boost/program_options/detail/utf8_codecvt_facet.hpp>#include <boost/locale.hpp>
#include <fstream>
std::ofstream txtFile;
std::locale oldLocale;
std::locale utf8Locale(oldLocale, new boost::program_options::detail::utf8_codecvt_facet());
txtFile.imbue(utf8Locale);
txtFile.open(txtPath, std::ios::app);
if (!txtFile)
{
throw -1;
}
txtFile<< boost::locale::conv::to_utf<char>(text,"gb2312");
txtFile.close();
本文介绍了一种利用Boost库中的program_options和locale组件来处理文本文件编码转换的方法。具体展示了如何将GB2312编码的字符串转换为UTF-8,并写入到文件中。

1万+

被折叠的 条评论
为什么被折叠?



