【发布时间】:2017-07-25 17:11:43
【问题描述】:
我正在尝试编写一个程序,将文件从一个目录移动到另一个目录,到目前为止我已经写好了。
void file_Move(ifstream in,ofstream out)
{
string name, name2;
int downloads;
cout << "Enter 1 if the file you wish to move is in downloads" << endl;
cin >> downloads;
if (downloads == 1)
{
opendir("F:/Downloads"); //supposed to open the directory so that the user can input the file they wish to be moved.
closedir("F:/Downloads");
}
}
Visual Studio 没有 opendir 和 closedir 所必需的 dirent.h 库,所以我想知道是否有类似或更好的方法来执行这些操作。
【问题讨论】:
-
处理目录需要特定于操作系统的函数,它不是 C++ 规范的一部分。
-
如果您询问的是 Win32 API,请在 MSDN 上查找 FindFirstFile 和 FindNextFile 以及相关函数。
-
@Barmar:实际上,它是委员会最近批准的即将正式发布的规范的一部分。
-
实际上,它是即将正式发布的规范的一部分 ...最后,不敢相信他们花了这么长时间。如果你不能等到 C++17,还有boost::filesystem::rename。