64,642
社区成员
发帖
与我相关
我的任务
分享
贴出错误信息?vs2013下编译通过 [quote=引用 7 楼 qq_32890755 的回复:] starytx,编译报错,呜呜
贴出错误信息?vs2013下编译通过 starytx,编译报错,呜呜
贴出错误信息?vs2013下编译通过 starytx,编译报错,呜呜
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;
// 根据后缀名判断是否是图片文件
bool IsImage(LPCTSTR szExten)
{
std::wstring str(szExten) ;
transform(str.begin(), str.end(), str.begin(), tolower); // 转化为小写
if (L"bmp" == str ||
L"png" == str ||
L"jpg" == str ||
L"jpeg" == str ||
L"gif" == str)
{
return true;
}
return false;
}
void find(LPCTSTR lpPath, std::vector<const std::wstring> &fileList)
{
TCHAR szFind[MAX_PATH] = { 0 };
WIN32_FIND_DATA FindFileData;
wcscpy_s(szFind, lpPath);
wcscat_s(szFind, _T("\\*.*"));
HANDLE hFind = ::FindFirstFile(szFind, &FindFileData);
if (INVALID_HANDLE_VALUE == hFind) return;
while (1)
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (FindFileData.cFileName[0] != '.')
{
TCHAR szFile[MAX_PATH] = { 0 };
wcscpy_s(szFile, lpPath);
wcscat_s(szFile, _T("\\"));
wcscat_s(szFile, (FindFileData.cFileName));
find(szFile, fileList);
}
}
else
{
std::wstring strFileName = FindFileData.cFileName;
std::wstring suffixStr = strFileName.substr(strFileName.find_last_of('.') + 1);
if (IsImage(suffixStr.c_str()))
{
std::wstring strFilePath = lpPath;
strFilePath += _T("\\");
strFilePath += FindFileData.cFileName;
//std::cout << FindFileData.cFileName << std::endl;
fileList.push_back(strFilePath);
}
}
if (!FindNextFile(hFind, &FindFileData)) break;
}
FindClose(hFind);
}
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, ("chs")); // 显示中文
std::vector<const std::wstring> fileList;
find(_T("C:\\testFrom"), fileList); // 遍历"C:\testFrom"文件夹,找到所有图片文件路径
std::wstring strTo;
for (int i = 0; i != fileList.size(); ++i)
{
strTo = L"C:\\testTo\\"; // 目标文件目录
strTo += fileList[i].substr(fileList[i].rfind('\\'));
wcout << fileList[i].c_str() <<endl;
CopyFile(fileList[i].c_str(), strTo.c_str(), FALSE);
}
return 0;
}
starytx,编译报错,呜呜