views:

30

answers:

2

I did a program in C++ but it does not allow to save on c:\SomeDirectory\afile.txt

I'm using this:

FILE* m_hFile = fopen("c:\\SomeDirectory\\afile.txt", "a+t");

fprintf((FILE *)m_hFile, "testing");

fclose(m_hFile);

Why that? Is there a defined folder I can save in?

+1  A: 

Windows 7 doesn't allow the creation of files in (subdirectories of?) the root directory. Maybe try running as admin.

Also, that's very C code, not C++. Use streams/good C++, not C with classes.

GMan
FYI: It does allow you create directories even as a normal user, not files though.
tyranid
@tyranid: Good to know.
GMan
@tyranid is right, but it still remains a good idea for @okami to run a test as admin (elevated, consenting to a UAC prompt) to rule out such issues.
Kate Gregory
+1  A: 

i assume the fopen() yields a valid m_hFile and the rest of the code does not crash either. since your program seems to not be run with admin-permissions that file will be 'redirected' to the 'virtual store'. search for the file in

%USERPROFILE%\AppData\Local\VirtualStore\SomeDirectory\afile.txt

essentially programs should only write to user-writable areas. read more about it here.

akira
That's certainly not true for all values of "SomeDirectory". If @okami has given us the real code, virtualization will not apply. Basically the root of C and Program Files are the virtualized ones.
Kate Gregory