如何从 Windows 中没有控制台窗口的 C++ 应用程序中删除文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/386559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete a file from a C++ app without console window in Windows?
提问by c0m4
I need to delete a temporary file from my C++ windows application (developed in Borland C++ Builder). Currently I use a simple:
我需要从我的 C++ windows 应用程序(在 Borland C++ Builder 中开发)中删除一个临时文件。目前我使用一个简单的:
system("del tempfile.tmp");
This causes a console window to flash in front of my app and it doesn't look very professional. How do I do this without the console window?
这会导致控制台窗口在我的应用程序前面闪烁,看起来不太专业。在没有控制台窗口的情况下如何执行此操作?
回答by SmacL
Or, even the standard C library function int remove( const char *path );
.
或者,甚至标准 C 库函数int remove( const char *path );
.
回答by Paul Stephenson
It sounds like you need the Win32 function DeleteFile(). You will need to #include <windows.h>
to use it.
听起来您需要 Win32 函数DeleteFile()。您将需要#include <windows.h>
使用它。
回答by Roger Nelson
For a slightly more portable (I.e. that works in both Windows and UNIX), I use unlink() or the ISO conformant _unlink() in io.h (unlink() for UNIX include unistd.h)
Remove() actually calls _unlink().
对于稍微更便携(即适用于 Windows 和 UNIX),我在 io.h 中使用 unlink() 或符合 ISO 的 _unlink()(UNIX 的 unlink() 包括 unistd.h)
Remove() 实际上调用 _unlink( )。