WritePrivateProfileString 设置为程序当前路径的方法

来源:互联网 发布:linux 开机执行命令 编辑:程序博客网 时间:2024/05/16 19:29

1. 通常的方法:  

    找到程序的绝对路径,  再计算得到绝对目录


char path1[MAX_PATH]={0};GetCurrentDirectory(MAX_PATH,path1);cout<<path1<<endl;char path2[MAX_PATH]={0};GetModuleFileName(NULL,path2,MAX_PATH);cout<<path2<<endl;

2.变通方法:

   通过相对目录, 虽然不能直接取当前目录, 但可以向下一层,再向上一层,即可变通得到当前目录.

WritePrivateProfileString("students","name","zhangsan","src/../students.ini");

   向下一层的目录名可以随便写,不需要实际存在. [本例中为:src]

   Remarks:  本方法只在Win7,VS2008下做过测试,如果哪位发现有例外的,欢迎留言.

原创粉丝点击