c语言如何获得文件当前路径?

c语言如何获得文件当前路径?,第1张

http://hi.baidu.com/andywangcn/item/7633efda5517baf9ca0c39c6

获得双斜杠路径不包含文件名春肆

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

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8213881.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存