How to write a file in the home directory


I would like to save an xml file in the home folder of the user. I have the following code :

But when I set fgFileName to “~/xxx.xml” it doesn’t seem to write the file (at least, I can’t find it).

How should I do ?

Thanks in advance


Hi, Barth

Output to the file in TXMLEngine implemented with ofstream class.
I am not sure, that this class supports any kind of shell variables like “~”.
If you want to write file in your home directory, either use getenv(“HOME”) or gSystem->HomeDirectory() call to find out that is real name of your home directory. In that case code will look like:

std::string fname = gSystem->HomeDirectory();
fname += "/xxx.xml";
xml->SaveDoc(xmldoc, fname.c_str());


It works perfectly, I should have thought about it !
Thanks a lot,