C/C++中如何表示上级和上上级路径?

来源:互联网 发布:博弈树搜索算法 编辑:程序博客网 时间:2024/05/17 01:01

       默认当前路径:

#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, 不多说.

 

 

原创粉丝点击