问题:编译失败
编译软件:Dev-C++
#include <iostream>
#include <filesystem>
#include <windows.h>
#include <shlobj.h>
void CopyFiles(const std::string &srcPath, const std::string &dstPath) {
std::filesystem::copy(srcPath, dstPath, std::filesystem::copy_options::overwrite_existing);
}
void SearchFiles(const std::string &path) {
std::filesystem::path searchPath(path);
searchPath /= ".";
WIN32_FIND_DATAA findData;
HANDLE handle = FindFirstFileA(searchPath.string().c_str(), &findData);
if (handle != INVALID_HANDLE_VALUE) {
do {
if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
std::string fileName(findData.cFileName);
if (fileName.size() >= 2 && fileName[1] == ':') {
char driveLetter[] = { fileName[0], ':', '\', '\0' };
UINT driveType = GetDriveTypeA(driveLetter);
if (driveType == DRIVE_REMOVABLE) {
// 创建子目录
std::string subDirName = "usb_files_" + fileName.substr(0, 2);
std::string subDirPath = path + "\" + subDirName;
std::filesystem::create_directory(subDirPath);
// 复制文件
std::string srcFile = fileName;
std::string dstFile = subDirPath + "\\" + fileName;
CopyFiles(srcFile, dstFile);
}
}
}
}
while (FindNextFileA(handle, &findData) != 0);
FindClose(handle);
}
}
int main() {
// 获取系统根目录
DWORD drives = GetLogicalDrives();
for (int i = 0; i < 26; i++) {
if ((drives & (1 << i)) != 0) {
char driveLetter[] = { 'A' + i, ':', '\', '\0' };
UINT driveType = GetDriveTypeA(driveLetter);
if (driveType == DRIVE_FIXED || driveType == DRIVE_REMOVABLE) {
SearchFiles(driveLetter);
}
}
}
return 0;
}
解释来源于Chit GBT :
1、DEV C 是一个比较老的集成开发环境,有一些功能和特性可能不支持或不适配目前的操作系统和硬件。
2、程序运行错误可能是代码本身有误,也可能是编译器/解释器版本问题。
3、DEV C 的用户体验和易用性没有现代开发工具那么好,可能需要更多的手动操作和调试。
4、使用不当或者没有正确安装必要的组件和库,也可能导致程序在 DEV C 中无法正常运行。
总的来说,造成在 DEV C++ 中运行错误的原因很多,需要根据具体的情况来排查。如果无法解决,可能需要考虑使用更现代的开发工具。