C++ CreateFile does not found .txt file in same folder as .exe [closed]

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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 means ERROR_FILE_NOT_FOUND

How is it even possible?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!