我在将Unicode(希腊)字符保存到文件时遇到问题,问题是程序的写入功能达到CString的希腊字符时。 保存英文字符没有问题。
我不知道我在代码中哪里做错了。
先谢谢了。
这是我的代码
void CCheckOmadesOroiDlg::SaveLathoiToFile()
{
CStringW sf;
CStringW str_to_save = L"";
str_to_save = L"Nikitria stili ";
for (int i = 0; i < 6; i++)
{
sf.Format(L"%d ", exada.vExades[geydomada].number[i]);
str_to_save += sf;
}
sf = L"\n\n";
str_to_save += sf;
sf.Format(L"Λαθοι Ομαδων απο=%d μεχρι=%d (%d)\n", glathoi.lathoiomadon_apo, glathoi.lathoiomadon_mexri, glathoi.lathoiomadon);
str_to_save += sf;
CString filename; filename.Format(_T("lathoi_%d.txt"), geydomada);
wofstream file(filename, ios::out);
streamsize n = str_to_save.GetLength()*sizeof(WCHAR);
file.write(str_to_save, n);
file.flush();
file.close();
}
答案 0 :(得分:0)
我找到了将Unicode字符写入文件的另一种方法。
这是代码。
void CCheckOmadesOroiDlg::SaveLathoiToFile()
{
CStringW sf;
CStringW str_to_save = L"";
str_to_save = L"Nikitria stili ";
for (int i = 0; i < 6; i++)
{
sf.Format(L"%d ", exada.vExades[geydomada].number[i]);
str_to_save += sf;
}
sf = L"\n\n";
str_to_save += sf;
sf.Format(L"Λαθοι Ομαδων απο=%d μεχρι=%d (%d)\n", glathoi.lathoiomadon_apo, glathoi.lathoiomadon_mexri, glathoi.lathoiomadon);
str_to_save += sf;
wchar_t* bufferwchar = new wchar_t[str_to_save.GetLength()];
bufferwchar = (wchar_t*)str_to_save.GetBuffer();
char filename[50]; sprintf_s(filename, "lathoi_%d.txt", geydomada);
FILE *stream;
// Open file in text mode:
if (fopen_s(&stream, filename, "wt,ccs=UNICODE") == 0)
{
fwrite(bufferwchar, sizeof(bufferwchar), str_to_save.GetLength()/2, stream);
fclose(stream);
}
}