2

My code is here:

//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; } 

I have tried many things, I can't remember them all to state them here. Such as changing the second parameter in fstream to ios::ate | ios::binary and such. I tried converting the empty text file to UTF, with and without BOM, I tried writing the BOM in the C++ code before writing any variables. I always just get a blank file.

Project encoding is Unicode character set. As a note, I really don't care what encoding the file will be, I will only be writing English character text to it. So as long as it writes the file I'm happy.

5
  • 1
    The answers to Wrote to a file using std::wofstream. The file remained empty might help Commented Nov 23, 2012 at 1:51
  • it says i should set std::locale::global(std::locale("Russian_Russia")); but im not using russian characters, its all english. Commented Nov 23, 2012 at 1:56
  • Have you done outputFile .flush() ? You can also try closing the stream before checking for data in the file... Commented Nov 23, 2012 at 2:23
  • just tried adding the outputFile.close(); at the end. i also tried the flush. it doesnt make any difference. Commented Nov 23, 2012 at 2:51
  • It depends on your OS and compiler. You may have to use std::setlocale(LC_ALL, "") as the first thing in your program (NOT std::locale::global(anything)). Commented Aug 25, 2013 at 15:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.