#include <cerrno>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
//...
passwd* pwd=getpwuid(getuid());
if (!pwd)
//Some error occurred.
//pwd->pw_dir now holds the user's ~ ("/home/nik", in this case).
//You should copy the string if you need to modify it.