TCHAR _szPath[MAX_PATH + 1]={0}
GetModuleFileName(NULL, _szPath, MAX_PATH)
(_tcsrchr(_szPath, _T('\\')))[1] = 0//删除文件名,只获得路径 字串
CString strPath
for (int n=0_szPath[n]n++)
{
if (_szPath[n]!=_T('\\'))
{
strPath +=_szPath[n]
}
else
{
strPath += _T("\\\\")
}
}
MessageBox(strPath)//输出==e:\\program\\Debug\扒败轿\
/枯散/头文件用到 windows.h
int main(){
string s = "c:\\abc\\def\\text.txt"
int xie_index = s.find_last_of('\\') // 路径中最后一个\的位置团携
string file_dirname = s.substr(0, xie_index + 1)
string file_basename = s.substr(xie_index + 1, s.size())
cout <<file_dirname <<endl <袭或慧拍答<file_basename <<endl
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)