windows vs 设置调试路径为exe所在的路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jacke121/article/details/88568542

windows vs 设置当前路径为exe所在的路径

将vs 代码中的当前路径指定为exe所在的路径
例如:fopen("./pic/a.txt", "r");
./ 是当前路径,这个路径可以设置为编译生成exe的路径,如下

    char sBuf[1024];
    char *ptr;
    if (GetModuleFileNameA(NULL, sBuf, sizeof(sBuf)))
    {
        ptr = strrchr(sBuf, '\\');
        if (ptr)
            *ptr = '\0';
        SetCurrentDirectoryA(sBuf);
    }


判断文件是否存在:

//
// 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/jacke121/article/details/88568542
今日推荐