the*_*gin 1 c++ windows winapi readonly
我想在Windows系统的c ++中检查.ini文件是否只读
例如:
if(file == readonly){
//Do this
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已尝试过这个并且它有效:
ofstream ofs(filename); //test to see if the file successfully opened for writing or not
Run Code Online (Sandbox Code Playgroud)
但结果它将删除.ini文件并将文件留空
PS:1.它不是重复的2.我在互联网上搜索过,我发现了一些可能有用的例子,但结果却没有按照他们的意愿进行编译.
如果您使用的是Windows,则可以使用:
DWORD attr = GetFileAttributes(filename);
if (attr != INVALID_FILE_ATTRIBUTES) {
bool isReadOnly = attr & FILE_ATTRIBUTE_READONLY;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1007 次 |
最近记录: |