为什么我不通过wofstream获得任何文件输出?

时间:2012-11-23 01:22:42

标签: c++ ofstream wofstream

我的代码在这里:

//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中的第二个参数更改为ios::ate | ios::binary等。我尝试将空文本文件转换为UTF,有或没有BOM,我尝试在编写任何变量之前在C ++代码中编写BOM。我总是得到一个空白文件。

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

0 个答案:

没有答案