C++获取路径中的文件名
(2017-04-28 16:42:30)
-
#include
-
#include
-
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
-
#include
-
#include
-
using namespace std;
-
void main()
-
{
-
string path="D:/osge/data/world.shp";
-
int pos=path.find_last_of('/');
-
string s(path.substr(pos+1));
-
cout<<s<<endl;
-
string path1="D:\osge\data\world.shp";
-
int pos1=path1.find_last_of('\\');
-
string s1(path1.substr(pos1+1));
-
cout<<s1<<endl;
-
}
喜欢
0
赠金笔
加载中,请稍候......