GetModuleFileName得到一個路徑在m_path中,怎么才能得到他上一級的路徑呢?
uj5u.com熱心網友回復:
???????uj5u.com熱心網友回復:
PathRemoveFileSpec
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"
#pragma comment(lib, "shlwapi.lib")
void main( void )
{
// Path to include file spec.
char buffer_1[ ] = "C:\\TEST\\sample.txt";
char *lpStr1;
lpStr1 = buffer_1;
// Print the path with the file spec.
cout << "The path with file spec is : " << lpStr1 << endl;
// Call to "PathRemoveFileSpec".
PathRemoveFileSpecA(lpStr1);
// Print the path without the file spec.
cout << "\nThe path without file spec is : " << lpStr1 << endl;
}
OUTPUT:
==================
The path with file spec is : C:\TEST\sample.txt
The path without file spec is : C:\TEST
uj5u.com熱心網友回復:

倒著字串查找/ \ 然后cut
uj5u.com熱心網友回復:
PathRemoveFileSpec 函式的作用:將路徑末尾的檔案名和反斜杠去掉。uj5u.com熱心網友回復:
#pragma comment(lib,"Shlwapi.lib")uj5u.com熱心網友回復:
其實就是char *slashAt=strrchr(defFileName,'\\');
if(slashAt) *slashAt=0;
uj5u.com熱心網友回復:
快使用C++17把 std::filesystem::path::parent_path()對于你的問題
CString parent_path(m_path);
parent_path = parent_path.Left(strPath.ReverseFind('\\')+1);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/13589.html
標籤:基礎類
上一篇:MFC串列控制元件關聯sql資料庫表想顯示出整張表但顯示不出
下一篇:求救
