关键词搜索

源码搜索 ×
×

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

发布2013-01-07浏览20493次

详情内容

       默认当前路径:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. FILE *fp = fopen("myData.txt", "w");
  5. fprintf(fp, "%d", 123);
  6. fclose(fp);
  7. return 0;
  8. }


      显式当前路径:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. // 在C中,'\'表示转义,故要用双斜杠
  5. FILE *fp = fopen(".\\myData.txt", "w");
  6. fprintf(fp, "%d", 123);
  7. fclose(fp);
  8. return 0;
  9. }


      上级路径:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. // 在C中,'\'表示转义,故要用双斜杠
  5. FILE *fp = fopen("..\\myData.txt", "w");
  6. fprintf(fp, "%d", 123);
  7. fclose(fp);
  8. return 0;
  9. }


      上上级路径:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. // 在C中,'\'表示转义,故要用双斜杠
  5. FILE *fp = fopen("..\\..\\myData.txt", "w");
  6. fprintf(fp, "%d", 123);
  7. fclose(fp);
  8. return 0;
  9. }


     利用相对路径很有好处,程序的移植性更好. OK, 不多说.

 

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载