每次都在以前代码中找这段代码,现在放上来,方便查找。
#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();