open file from root directory

How do you open a file from the root directory without have to type the complete path?

1
2
3
4
5
6
7
8
9
string path = "~/data/";
string file = path + "file.dat";

fstream f;
f.open(file.c_str(), ios::in);
if ( !f )
{
 cout << "I can't open " << file << "\n";
}


It prints it can't open the file.

But if I write

 
string path = "/home/nik/data/"; // my user directory 


it works well. Why???
closed account (S6k9GNh0)
Maybe it can't do '~'.
Last edited on
@nikola17681: Please don't post the same question in two topics.
I know, I made a mistake. I'm sorry.

My problem has solved here: http://www.cplusplus.com/forum/general/10361/
Topic archived. No new replies allowed.