默认当前路径:
#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, 不多说.
最后
以上就是神勇发箍最近收集整理的关于C/C++中如何表示上级和上上级路径?的全部内容,更多相关C/C++中如何表示上级和上上级路径内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复