本文介绍了我无法打开.txt文件,即使它们位于正确的目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好,首先,对不起,如果这是一个错误的地方提出这个问题Hi hello so first of all, sorry if this is the wrong place to put this question我无法让它成功打开我的文件。下面是一个不起作用的代码示例:I can't get it to open my files successfully. Here's an example of code that won't work: ifstream inFS;ifstream inFS; inFS.open(" exam.txt"); if(!inFS.is_open()){ cout<< "无法打开exam.txt" << endl; 返回0; }inFS.open("exam.txt");if (!inFS.is_open()) {cout << "Could not open exam.txt" << endl;return 0;}它运行代码并告诉我它无法打开它。我有\ConsoleApplication2 \ConsoleApplication2 \中的文件,我知道它的目的是指向。我将工作目录设置为它。它仍然无法打开它们。It runs through the code and tells me it can't open it. I have the file in \ConsoleApplication2\ConsoleApplication2\ where i KNOW it's meant to direct to. I set the working directory to it. It still won't open them.请告知(,,,:谢谢推荐答案出于诊断目的,请尝试添加 GetCurrentDirectory以确保您在目录中。以下适用于我。For diagnostic purposes, try adding a GetCurrentDirectory to ensure you are in the directory. The following works for me.TCHAR Buffer[MAX_PATH];DWORD dwRet;dwRet = GetCurrentDirectory(MAX_PATH, Buffer);std::wcout << Buffer << std::endl;std::ifstream inFS;inFS.open("exam.txt");if (!inFS.is_open()) {std::cout << "Could not open exam.txt" << std::endl;return 0;}std::cout << "Opened\n"; 这篇关于我无法打开.txt文件,即使它们位于正确的目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!