gpt4 book ai didi

c++ - 将文件作为参数传递给 Visual Studio

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:24:02 24 4
gpt4 key购买 nike

我尝试在 VS2010 中调试程序。在 Windows PowerShell 中,我键入 ./Nbody.exe ./config.txt。但是,当我在 Property Manager 窗口的命令参数表单调试部分输入 .\config.txt 或其他形式时,我的程序似乎无法找到该文件。事实上,我的这部分代码响应:

ifstream CSVfile(CSVFileName);

if (CSVfile == NULL) {
cout << "ERROR: Cannot Open CSV file" << endl;
exit(1);
}

最佳答案

Visual studio 计算从 working dir 路径开始的相对路径。因此,您必须使用 visual studio 变量作为 $(ProjectDir) 来复合文件的路径。

类似于:$(ProjectDir)\config.txt,否则您必须设置相对于 working dir 路径的路径。

假设您的结构是这样的:

project_name
+ project_name
| project_name.sln
| debug
| project_name.exe
| config.txt
+ ipch

并且您有 .\project_name\project_name 作为工作目录。

您在项目配置中输入的用于调试的路径必须相对于工作目录:

..\debug\config.txt

更新

正如@Goku 在他的(我假设 Goku 是一个“他”,:))评论中所述:

For VS2017, $(ProjectDir) already contained a '\' concatenated on the directory name.

关于c++ - 将文件作为参数传递给 Visual Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21881185/

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