C++中的文件系统
file systems in C++
我正在做一个项目,我必须在其中处理一些文件。
要是有人能告诉我如何使用文件系统就好了
移动、复制、删除、重命名和检查 Windows.
中的文件是否存在
检查 msdn 上的 file management functions 部分。
例如,要使用 WinAPI 复制文件,您可以使用 CopyFile:
#include <windows.h>
#include <iostream>
int main()
{
BOOL ret = CopyFile(TEXT("test.txt"), TEXT("test-copy.txt"), TRUE);
if (ret)
std::cout << "CopyFile failed. GetLastError:" << GetLastError() << std::endl;
}
如果您的编译器支持,您也可以使用可移植的 std::filesystem(例如,该代码在 windows 和 linux 上应该同样有效):
#include <filesystem>
int main()
{
std::filesystem::copy("test.txt", "test-copy.txt");
}
还有 boost::filesystem 对 std::filesystem 影响很大。
我正在做一个项目,我必须在其中处理一些文件。
要是有人能告诉我如何使用文件系统就好了 移动、复制、删除、重命名和检查 Windows.
中的文件是否存在检查 msdn 上的 file management functions 部分。
例如,要使用 WinAPI 复制文件,您可以使用 CopyFile:
#include <windows.h>
#include <iostream>
int main()
{
BOOL ret = CopyFile(TEXT("test.txt"), TEXT("test-copy.txt"), TRUE);
if (ret)
std::cout << "CopyFile failed. GetLastError:" << GetLastError() << std::endl;
}
如果您的编译器支持,您也可以使用可移植的 std::filesystem(例如,该代码在 windows 和 linux 上应该同样有效):
#include <filesystem>
int main()
{
std::filesystem::copy("test.txt", "test-copy.txt");
}
还有 boost::filesystem 对 std::filesystem 影响很大。