首页 > 其他分享 >在visual studio 2017中realpath在<cstdlib>头文件中未定义如何解决?

在visual studio 2017中realpath在<cstdlib>头文件中未定义如何解决?

时间:2022-12-12 11:23:48浏览次数:53  
标签:realpath 头文件 函数 未定义 abs path 2017

在 Visual Studio 2017 中,realpath 函数不在 头文件中,因为它属于 POSIX 标准而不是 C 标准。要使用 realpath 函数,你可以在你的代码中包含头文件 <stdlib.h> 并使用函数名 _fullpath 代替。这个函数的功能和 realpath 函数相同。

例如:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv) {
  if (argc != 2) {
    printf("Usage: myprogram <path>\n");
    return 1;
  }

  char* abs_path = _fullpath(NULL, argv[1], 0);
  printf("The absolute path is: %s\n", abs_path);

  free(abs_path);

  return 0;
}

标签:realpath,头文件,函数,未定义,abs,path,2017
From: https://www.cnblogs.com/mrpeng2333/p/16975546.html

相关文章