vs 设置调试路径为exe所在的路径
【摘要】
windows vs 设置当前路径为exe所在的路径
将vs 代码中的当前路径指定为exe所在的路径 例如:fopen("./pic/a.txt", "r"); ./ 是当前路径,这个路径可以设置为编译生成exe的路径,如下
#include <string.h>#include <Windows.h>...
windows vs 设置当前路径为exe所在的路径
将vs 代码中的当前路径指定为exe所在的路径
例如:fopen("./pic/a.txt", "r");
./ 是当前路径,这个路径可以设置为编译生成exe的路径,如下
-
#include <string.h>
-
#include <Windows.h>
-
char sBuf[1024];
-
char *ptr;
-
int main(int argc, char* argv[]) {
-
-
if (GetModuleFileNameA(NULL, sBuf, sizeof(sBuf)))
-
{
-
ptr = strrchr(sBuf, '\\');
-
if (ptr)
-
*ptr = '\0';
-
SetCurrentDirectoryA(sBuf);
-
}
-
return 0;
-
}
判断文件是否存在:
-
//
-
// Some utility functions
-
//
-
bool fileExists(const char *file)
-
{
-
struct stat st;
-
if(!file) return false;
-
int result = stat(file, &st);
-
return (0 == result);
-
}
-
-
// Early exits
-
if(!fileExists(INPUT_DATA_FILE) || !fileExists(INPUT_CFG_FILE) || !fileExists(INPUT_WEIGHTS_FILE))
-
{
-
EPRINTF("Setup failed as input files do not exist or not readable!\n");
-
return -1;
-
}
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/88568542
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)