Diffrent behaviour-VisualStudio Debugger against running exe

Diffrent behaviour-VisualStudio Debugger against running exe

本文关键字:running exe against Debugger behaviour-VisualStudio Diffrent      更新时间:2023-10-16

ediT:我找到了差异的原因:只有在Visual Studio中才会打开输入文件(它们被添加到解决方案中,(更重要的是)放置在解决方案Windows目录中),所以它在那里工作。

但是当我尝试运行生成的 EXE 文件时,它不会读取这些文件,因为文件路径字符串(在 VS 中工作)"../文件名"

任何建议(因此在两种情况下都有效)?

在主代码中:

string testFileName = "LEGACY_R48_800BITS_@40MHz.dat"; //channel output file name
string bitsFileName = "sentBits4.dat"; //original sent bits file name,NO initial zero added
//Works in Visual Studio only 
string path = __FILE__; //gets source code path, include file name
    path = path.substr(0,1+path.find_last_of('')); //removes file name
    path1= path+testFileName; //adds input file to path
path2=path+bitsFileName; //adds input file to path

//Works in Application EXE only
path1= testFileName;
path2=bitsFileName;

Visual Studio调试器中设置"工作目录"。

在"解决方案资源管理器"中选择项目后,在"项目"菜单上单击"属性"。单击调试选项卡。在 工作目录 字段中,输入将从中启动项目的目录。