默认当前路径:
- #include <stdio.h>
-
- int main()
- {
- FILE *fp = fopen("myData.txt", "w");
- fprintf(fp, "%d", 123);
- fclose(fp);
-
- return 0;
- }
显式当前路径:
- #include <stdio.h>
-
- int main()
- {
- // 在C中,'\'表示转义,故要用双斜杠
- FILE *fp = fopen(".\\myData.txt", "w");
- fprintf(fp, "%d", 123);
- fclose(fp);
-
- return 0;
- }
上级路径:
- #include <stdio.h>
-
- int main()
- {
- // 在C中,'\'表示转义,故要用双斜杠
- FILE *fp = fopen("..\\myData.txt", "w");
- fprintf(fp, "%d", 123);
- fclose(fp);
-
- return 0;
- }
上上级路径:
- #include <stdio.h>
-
- int main()
- {
- // 在C中,'\'表示转义,故要用双斜杠
- FILE *fp = fopen("..\\..\\myData.txt", "w");
- fprintf(fp, "%d", 123);
- fclose(fp);
-
- return 0;
- }
利用相对路径很有好处,程序的移植性更好. OK, 不多说.

![[手游] 三网H5小游戏【少年仙路】WIN系服务端+Linux手工服务端+详细搭建教程](https://cdn.jxasp.com:9143/image/20260615/136BC33AA47EB0D84E878835A8B38FDB.png)

















