加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C++获取路径中的文件名

(2017-04-28 16:42:30)
分类: c/c
  1. #include  
  2. #include  
  3. using namespace std;  
  4. void main()  
  5.   
  6.     char *file;    
  7.     file="E:/图片/Saved Pictures/7.jpg"   
  8.     char szDrive[_MAX_DRIVE];   //磁盘名  
  9.     char szDir[_MAX_DIR];       //路径名  
  10.     char szFname[_MAX_FNAME];   //文件名  
  11.     char szExt[_MAX_EXT];       //后缀名  
  12.     _splitpath(file,szDrive,szDir,szFname,szExt); //分解路径  
  13.     cout<<szDrive<<endl;  
  14.     cout<<szDir<<endl;  
  15.     cout<<szFname<<endl;  
  16.     cout<<szExt<<endl;  
  17.  
  18. //  *************************************  
  19. #include  
  20. #include  
  21. #include  
  22. using namespace std;  
  23. void main()  
  24.  
  25.     string path="D:/osge/data/world.shp";  
  26.     int pos=path.find_last_of('/');  
  27.     string s(path.substr(pos+1));  
  28.     cout<<s<<endl;  

   
  1.     string path1="D:\osge\data\world.shp";  
  2.     int pos1=path1.find_last_of('\\');  
  3.     string s1(path1.substr(pos1+1));  
  4.     cout<<s1<<endl;  
  1.  

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有