如何取得相对路径

    技术2022-05-11  36

    #include <windows.h> #include <iostream.h> #include "Shlwapi.h" void main(void) { char szOut[MAX_PATH] = ""; char szFrom[ ] = "c://a//b//path"; char szTo[ ] = "c://a//x//y//file"; cout << "The relative path is relative from: "; cout << szFrom; cout << "/n"; cout << "The relative path is relative to: "; cout << szTo; cout << "/n"; PathRelativePathTo(szOut, szFrom, FILE_ATTRIBUTE_DIRECTORY, szTo, FILE_ATTRIBUTE_NORMAL); cout << "The relative path is: "; cout << szOut; cout << "/n"; }

     

    OUTPUT: ================== The relative path is relative from: c:/a/b/path The relative path is relative to: c:/a/x/y/file The relative path is: ../../x/y/file


    最新回复(0)