I have SOME_TEXT.TXT in the Debug folder for my project. When I manually go to the Debug folder and run the application, I get the expected output and all is glorious. However, when I Debug the app within Visual Studio txtFile.is_open() fails and my output doesn't work. I've looked around in the other directories and I see no other executable. I've even tried liberally spreading SOME_TEXT.TXT around in case I missed a directory. Any ideas?
我在项目的Debug文件夹中有SOME_TEXT.TXT。当我手动转到Debug文件夹并运行应用程序时,我得到了预期的输出,而且一切都是光荣的。但是,当我在Visual Studio中调试应用程序时,txtFile.is_open()失败并且我的输出不起作用。我在其他目录中环顾四周,我看不到其他可执行文件。我甚至尝试过大量传播SOME_TEXT.TXT以防万一我错过了一个目录。有任何想法吗?
I have the following code:
我有以下代码:
string path = "SOME_TEXT.TXT";
ifstream txtFile;
txtFile.open(path, ifstream::in);
char line[200];
if(txtFile.is_open())
{
int lineNumber = 1;
while(!txtFile.eof())
{
txtFile.getline(line, 200);
Line * ln = new Line(line, path, lineNumber);
lineNumber++;
myList.addLine(ln);
}
}
myList.printAll();
1 个解决方案
#1
1
You can control the working directory your program will run at in properties in the context menu of your project. Then in the "Debug" tab.
您可以在项目的上下文菜单中的属性中控制程序将运行的工作目录。然后在“调试”选项卡中。
This directory defaults to the output directory of the executable. Note that the output directory for release and debug are different. They are typically called "Debug" and "Release".
此目录默认为可执行文件的输出目录。请注意,发布和调试的输出目录是不同的。它们通常称为“调试”和“发布”。
Try to stick your text file in the Debug folder.
尝试将文本文件粘贴到Debug文件夹中。
#1
1
You can control the working directory your program will run at in properties in the context menu of your project. Then in the "Debug" tab.
您可以在项目的上下文菜单中的属性中控制程序将运行的工作目录。然后在“调试”选项卡中。
This directory defaults to the output directory of the executable. Note that the output directory for release and debug are different. They are typically called "Debug" and "Release".
此目录默认为可执行文件的输出目录。请注意,发布和调试的输出目录是不同的。它们通常称为“调试”和“发布”。
Try to stick your text file in the Debug folder.
尝试将文本文件粘贴到Debug文件夹中。