VC获取当前文件路径---比较

方法一:

void GetAppPath(wstring &sPath)
{
	sPath.resize(MAX_PATH);
	::GetModuleFileName(GetModuleHandle(NULL), (LPTSTR)sPath.c_str(), MAX_PATH);
	int index = sPath.find_last_of(L'\\');
	if(index >= 0) sPath = sPath.substr(0, index);
}

方法二:

CString GetCurrPath()
{
	char fullpath[256] = {0};
	GetModuleFileName(NULL, fullpath, MAX_PATH);
	CString cspath(fullpath);
	int index = cspath.ReverseFind('\\');
	return cspath.Left(index);
}
方法三:

{
    char lpFileName[MAX_PATH];    
    GetModuleFileName(NULL, lpFileName, sizeof(lpFileName));
    char* p = strrchr(lpFileName, '\\'); 
    if( p )
        *p = 0;
}


你可能感兴趣的:(VC获取当前文件路径---比较)