gpt4 book ai didi

c++ - .CPP 文件和 .EXE 文件逻辑不一致

转载 作者:行者123 更新时间:2023-11-28 02:55:11 27 4
gpt4 key购买 nike

我以前从来没有遇到过这个问题,当我构建我的代码时,主要错误检查语句是否在控制台中正确运行。

ifstream inputfile;
inputfile.open("arrayNumbers.txt");

if(inputfile) //<----- This is working correctly in the CPP, but not in the EXE
{

不幸的是,当我去运行可执行文件时,if 语句被踢到“文件未打开”else 部分

else
{
cout << "File did not open" << endl;
//^^^^In the exe, the program skips the rest of the code and kicks here
}

有人知道为什么会这样吗?

编译器是 Visual Studio 2010

我也在调试和 Release模式下运行了它

最佳答案

这可能与文件 arrayNumbers.txt 的存储位置有关,将文件移动到与可执行文件相同的文件夹中,它应该可以工作。

关于c++ - .CPP 文件和 .EXE 文件逻辑不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22163813/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com