不同的行为 - 针对运行exe的Visual Studio Debugger

时间:2013-10-06 09:59:09

标签: c++ visual-studio visual-studio-2012

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

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

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

在主要代码中:

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;

1 个答案:

答案 0 :(得分:1)

在Visual Studio调试器中设置“工作目录”。

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