C++ 如何在.txt文件中保存泰语
我想在编辑控件中将文本作为泰语字符保存在.txt文件中。问题是在.txt文件中,泰国字符显示为C++ 如何在.txt文件中保存泰语,c++,visual-studio-2008,mfc,text-files,C++,Visual Studio 2008,Mfc,Text Files,我想在编辑控件中将文本作为泰语字符保存在.txt文件中。问题是在.txt文件中,泰国字符显示为?,但英文字符和数字没有问题 我该怎么做 char* getStringFromCString(CString& x) // code convert string { char * temp = new char[(x.GetLength()) + 1]; int i = 0; for (; i < x.GetLength(); i++) {
?
,但英文字符和数字没有问题
我该怎么做
char* getStringFromCString(CString& x) // code convert string
{
char * temp = new char[(x.GetLength()) + 1];
int i = 0;
for (; i < x.GetLength(); i++)
{
temp[i] = x[i];
}
temp[i] = '\0';
return temp;
}
void CPictureDlg::OnBnClickedButtonSave() // Save.txt files
{
CString ss[2];
CITIZEN_ID.GetWindowTextW(ss[0]);
Name_text.GetWindowTextW(ss[1]);
char* citizen = getStringFromCString(ss[0]);
char* name = getStringFromCString(ss[1]);
std::ofstream myfile;
myfile.open("example.txt", std::ios::out | std::ios::app);
myfile << citizen << "\t" << name;
myfile.close();
UpdateData(FALSE);
}
char*getStringFromCString(CString&x)//代码转换字符串
{
char*temp=new char[(x.GetLength())+1];
int i=0;
对于(;i
问题
首先,你必须使用Unicode。请阅读这个。
其次,您的getStringFromCString()
存在内存泄漏问题
- 方法
对泰国字符集使用Unicode和std:wofstream
,std:locale
std::wofstream myfile;
//I just checked for Korean, you may need std::locale("thai").
myfile.imbue(std::locale("kor"));
myfile.open("example.txt", std::ios::out | std::ios::app);
myfile << input.GetString();
myfile.close();
std::wofstream myfile;
//我刚刚检查了韩语,您可能需要std::locale(“泰语”)。
imbue(std::locale(“kor”);
打开(“example.txt”,std::ios::out | std::ios::app);
myfile您如何检查.txt
文件?您知道该工具使用什么编码吗?在编写名称文本时使用什么编码?以及名称文本的类型是什么?MFC中的MBCS支持已被弃用。您应该改为使用Unicode来准备代码以备将来使用。这不是什么新闻。Windows-NT系列产品已经在内部使用Unicode超过20年了(NT 3.1)。其他要求阅读: