默认当前路径:
#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, 不多说.
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow