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

<pre name="code" class="cpp">#include<iostream>
#include<fstream>
using namespace std;
void main()
{ 
    char *file;  
    file="E:/图片/Saved Pictures/7.jpg";  
    char szDrive[_MAX_DRIVE];   //磁盘名
	char szDir[_MAX_DIR];       //路径名
	char szFname[_MAX_FNAME];   //文件名
	char szExt[_MAX_EXT];       //后缀名
	_splitpath(file,szDrive,szDir,szFname,szExt); //分解路径
	cout<<szDrive<<endl;
	cout<<szDir<<endl;
	cout<<szFname<<endl;
	cout<<szExt<<endl;
}
//  *************************************
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void main()
{
	string path="D:/osge/data/world.shp";
	//char *p=strrchr(path.c_str(),'/');
	int pos=path.find_last_of('/');
	string s(path.substr(pos+1));
	cout<<s<<endl;
}



   

原文地址:https://www.cnblogs.com/zztong/p/6695201.html