#include <iostream>
#include <sstream>
#include <fstream>
std::string UnicodeToANSI(const std::wstring& str)
{
char* pElementText;
int iTextLen;
// 宽字节转多字节
iTextLen = WideCharToMultiByte(CP_ACP, 0,
str.c_str(),
-1,
nullptr,
0,
nullptr,
nullptr);
pElementText = new char[iTextLen + 1];
memset((void*)pElementText, 0, sizeof(char) * (iTextLen + 1));
::WideCharToMultiByte(CP_ACP,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
nullptr,
nullptr);
std::string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
std::wstring strOutFile = L"C:\\Users\\Administrator\\Desktop\\新建文本文档.txt";
std::ofstream fStream;
fStream.open(strOutFile, std::ios::out | std::ios::binary);
std::wstringstream stream;
stream.setf(std::ios::fixed);
stream.precision(6);
stream << L"def __eval_cal():";
fStream << UnicodeToANSI(stream.str());
fStream.close();