Loading

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

在 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;
}
posted @ 2022-12-12 11:07  xaopng  阅读(345)  评论(0)    收藏  举报