Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
K

Kurukuru

Guest
Original poster
Is it possible to open a file in the current user's home folder by doing something like (in C++):
ifstream fIn("/~/somefile.ext", ios::binary);

I know the code above does not work, but I wonder if there's anything like it available?

Or do you have to examine the HOME environment variable?
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
The reason "/~/somefile.ext" doesn't work is because "~" cannot have anything before it on Unix.

If you use "~/Library/Preferences/MyFile.ext", it will put the file in the current user's preferences folder. If you use "/~/Library/Preferences/MyFile.ext", it simply won't work.

This is supported on every API on OS X that takes a file path.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.