ofstream %appdata%

So i've this part of code:

1
2
3
ofstream file;

file.open("C:\\Users\\Mario\\AppData\\Roaming\\DoDLog.log", ios::out | ios::app);


obviously this will work only on my computer where my windows partition is C:\ and my username is Mario.
If i try
1
2
3
ofstream file;

file.open("%appdata%\\DoDLog.log", ios::out | ios::app);

this doesn't work!
So how i can get the appdata path and put it into first parameter?

i've tryed this
1
2
3
4
5
6
  char* Path;
  Path = getenv ("appdata");
  
  ofstream file;

  file.open(Path + "DoDLog.log", ios::out | ios::app);


but this doesn't work for some variables conversion issue
How can i solve this?
Last edited on
Try this instead:

1
2
3
4
5
6
7
8
9
10
11
12
int main ()
{   string  path;
    ofstream file;
  
    path = getenv ("appdata");
    cout << "appdata=" << path << endl;
    path += "\\DoDLog.log";
    cout << "path=" << path << endl;
    file.open(path.c_str(), ios::out | ios::app);
    system ("pause");
    return 0;
}

Topic archived. No new replies allowed.