How can I get rid of this error and other while compiling the below code?
#include "stdafx.h" #include <string> #include <vector> #include <windows.h> #include <atlstr.h> #include <tchar.h> #include <stdio.h> #define MAX_PATH_LENGTH 256 int main(int argc, char *argv[]) { int i; char path[300]; bool FindFilesFromFolder(); getchar(); return 0; } bool FindFilesFromFolder() { HANDLE hFile; WIN32_FIND_DATA FindFileData; std::vector<char> fileList; char chFolderpath[_MAX_PATH]; CString strExtension = _T("*.B11"); strcpy(chFolderpath, _T("F:\\test\\")); strcat(chFolderpath, strExtension); hFile = FindFirstFile(chFolderpath, &FindFileData); if (hFile == INVALID_HANDLE_VALUE) { AfxMessageBox(_T("Inavlid file handle.")); return false; } CString filepath; do { filepath.Format(_T("%s%s"), _T("F:\\test\\"), FindFileData.cFileName); fileList.push_back(filepath); } while(FindNextFile(hFile, &FindFileData)); return true; }
Yes this is an example to know the correct usage of findfirstfile()
. I got strcpy
errors too.
Error:error C2664: 'strcpy' : cannot convert parameter 2 from 'const wchar_t [9]' to 'const char *'. Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.
Error: error C2664: 'strcat' : cannot convert parameter 2 from 'ATL::CString' to 'const char *'. No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called.
Error:error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'ATL::CString' to 'const char &' with
It gives all conversion errors; how to solve these errors?