If i write

ofstream log(TEXT("С:\\TEST\\log.txt"),ios::app); 

Then it will work for me only if instead of the system disk (C) there is any other. Create directory via

 CreateDirectory(TEXT("C:\\TEST"), NULL); 

it turns out easily. But the file itself to create somewhere on the C drive does not work. It is desirable for me to implement this somehow through ofstream.

  • Running a separate source on behalf of the administrator did not give anything. - Ubronies

1 answer 1

In general, I figured out this issue. As I understand it, you can create files easily in the folder and subfolders after AppData, but on each computer there are different user names. However, this is also very easily solved. The getenv ("APPDATA") function gets the location to the Roaming folder, and then you just have to attach the full path to it and voila, it's done))

 strcpy(dir, getenv("APPDATA")); strcat(dir, "\\Microsoft\\"); strcat(logName, dir); //dir- это если вам еще для чего-то надо будет директория. strcat(logName, "\\log.txt"); ofstream log(logName, ios::app); // и вы создали файл txt на диске С))