C++ CreateFile does not found .txt file in same folder as .exe [closed]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use CreateFile function, but it does not go as planned. I did a simple test code : #include <Windows.h> #include <iostream> #include <tchar.h> using namespace std; int main() { HANDLE hFile; hFile = CreateFile(_T("test.txt"), GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL); if (hFile == INVALID_HANDLE_VALUE) { cout << GetLastError() << endl; Sleep(2000); return EXIT_FAILURE; } return EXIT_SUCCESS; } I generate the .exe and place a file test.txt in the same folder. When I execute the .exe I get getLastError() = 2 which