gpt4 book ai didi

c++ - 从 Windows 网络位置打开文件

转载 作者:可可西里 更新时间:2023-11-01 12:09:09 25 4
gpt4 key购买 nike

我可以从已安装的网络驱动器打开文件,但不能从未安装的网络驱动器打开文件,例如\\mycomp\folder2\hi.bmp

有什么解决办法吗?

最佳答案

以下代码片段对我有用:

char buffer[1000];    
FILE* file;
size_t bytesRead;

file = fopen("\\\\server\\share\\test.dat", "rb");
if (file != NULL)
{
bytesRead = fread(buffer, sizeof(char), sizeof(buffer), file);
fclose(file);
}

另请注意 fopen docs (MSDN) 中的这段摘录:

...

fopen will accept paths that are valid on the file system at the point of execution; UNC paths and paths involving mapped network drives are accepted by fopen as long as the system executing the code has access to the share or mapped network drive at the time of execution. Special care must be taken when constructing paths for fopen to avoid making assumptions about available drives, paths or network shares in the execution environment.
...

您还需要考虑,您运行程序所使用的帐户需要对文件具有适当的访问权限。当您将共享安装为网络驱动器时,您可能正在使用不同的凭据进行连接。这可能会导致 fopen 失败。

关于c++ - 从 Windows 网络位置打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3308245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com