在C中打开另一个目录中的文件

发布于 2024-08-07 05:27:34 字数 327 浏览 2 评论 0原文

这是如何实现的?我想使用

pFile = fopen( file, "rb" );

Where file is a char, string or long 包含包含二进制文件本地路径的文字文本,

C:\Documents and Settings\Supernovah\Desktop\Supernovah.bin

但这当然会崩溃。

我还对如何以可移植的方式重复当前目录感兴趣。 windows.h 有点难看,但如果我不能以可移植的方式做到这一点。就这样吧。

谢谢 :)

How is this achieved? I want to use

pFile = fopen( file, "rb" );

Where file is a char, string or long containing the literal text containing a local path to a binary file

C:\Documents and Settings\Supernovah\Desktop\Supernovah.bin

but of course that crashes.

I am also interested in how to recur over the current directory in a portable way. windows.h is a little ugly but if I can't do it in a portable way. So be it.

thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2024-08-14 05:27:34
char* file="C:\\Documents and Settings\\Supernovah\\Desktop\\Supernovah.bin";
FILE* pFile = fopen( file, "rb" );
char* file="C:\\Documents and Settings\\Supernovah\\Desktop\\Supernovah.bin";
FILE* pFile = fopen( file, "rb" );
何以笙箫默 2024-08-14 05:27:34

GCC/MinGW 和 VC++ 2008(可能还有其他)都允许 Win32 中的 Unix 样式路径分隔符。 so:

char* file="C:/Documents and Settings/Supernovah/Desktop/Supernovah.bin";

也可以工作,并且可以在操作系统之间移植。然而,路径中的空格可能会出现问题,需要在 Linux 中替换为 %20。

Both GCC/MinGW and VC++ 2008 (and probably others) allow Unix style path delimiters in Win32. so:

char* file="C:/Documents and Settings/Supernovah/Desktop/Supernovah.bin";

would work as well, and is portable between operating systems. Spaces in paths however may be problematic, requiring replacement with %20 in Linux.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文