I use tinyXml to store configuration file under FOLDERID_RoamingAppData, or in other words, under C:\Users\USERNAME\AppData\Roaming. I use the following sequence (simplified):
I wonder how I can LoadFile/SaveFile when the filename contains non-latin (e.g. Hebrew) characters.
There is no portable way to codify Windows filenames in char
-based variables (C-strings or std::string
s), since the Windows API does not accept the UTF8 encoding.
Luckily, TinyXml offers an alternative form of LoadFile
, accepting a FILE*
as argument. You can use the Windows _wfopen
to get such handle: here is a snippet:
SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &path);
FILE* xmlFile = _wfopen(path, L"r+");
m_doc.LoadFile(xmlFile);
The corresponding function SaveFile
works in the same manner – in this case use L"w"
as second parameter of the _wfopen
call to overwrite the previous version of the file.