2

我的代码在这里:

//wstring filename = temp.name + L".txt";
wstring filename = L"hero2.txt";
//wofstream File(filename.c_str());
wofstream outputFile(L"temp.txt", ios::ate | ios::binary);
if (outputFile.fail()) windowmsg(1, LPCWSTR(L"Could not Save game"));
else windowmsg(1, LPCWSTR(L"Game Saved"));

wchar_t BOM = 0xFEFF;//Byte Order Mark character
outputFile << BOM;

outputFile << temp.name << endl;
outputFile << temp.lvl << endl;
outputFile << temp.HP <<endl;
outputFile << temp.minHP <<endl;
outputFile << temp.MP <<endl;
outputFile << temp.minMP <<endl;
outputFile << temp.ATK <<endl;
outputFile << temp.DEF <<endl;
outputFile << temp.mATK <<endl;
outputFile << temp.mDEF <<endl;
outputFile << temp.SPD <<endl;
outputFile << temp.exp <<endl;
outputFile << temp.exptonext <<endl;
outputFile << temp.gearnumber <<endl;
for (int count = 0 ; count < temp.gearnumber ; count++)
{
    outputFile << temp.equip[count].name <<endl;
    outputFile << temp.equip[count].type <<endl;
    outputFile << temp.equip[count].ATK <<endl;
    outputFile << temp.equip[count].DEF <<endl;
    outputFile << temp.equip[count].mATK <<endl;
    outputFile << temp.equip[count].mDEF <<endl;
    outputFile << temp.equip[count].SPD <<endl;
}

我已经尝试了很多东西,我不记得它们都在这里陈述它们。比如把fstream中的第二个参数改成to ios::ate | ios::binary等。我尝试将空文本文件转换为 UTF,有和没有 BOM,我尝试在编写任何变量之前在 C++ 代码中编写 BOM。我总是得到一个空白文件。

项目编码是 Unicode 字符集。作为说明,我真的不在乎文件的编码是什么,我只会向它写入英文字符文本。所以只要它写文件我很高兴。

4

0 回答 0