开发者

How to save a file with C++ in Windows 7

开发者 https://www.devze.com 2023-01-23 02:23 出处:网络
I did a program in C++ but it does not allow to sav开发者_如何转开发e on c:\\SomeDirectory\\afile.txt

I did a program in C++ but it does not allow to sav开发者_如何转开发e 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消