C++:从完整路径中提取文件名、不带后缀的名字、后缀名

#include <iostream> 
#include <string>
using namespace std;
void main()
{
    string path = "C:\\Users\\Administrator\\Desktop\\text\\data.22.txt";
     
    //1.获取不带路径的文件名
    string::size_type iPos = path.find_last_of('\\') + 1;
    string filename = path.substr(iPos, path.length() - iPos);
    cout << filename << endl;
  
    //2.获取不带后缀的文件名
    string name = filename.substr(0, filename.rfind("."));
    cout << name << endl;
  
    //3.获取后缀名
    string suffix_str = filename.substr(filename.find_last_of('.') + 1);
    cout << suffix_str << endl;
}
ID:9 score 0.902637 (l,t,r,b)[747, 1104, 1039, 1331]
ID:9 score 0.895594 (l,t,r,b)[105, 1449, 623, 1687]
ID:9 score 0.892932 (l,t,r,b)[1044, 1109, 1260, 1323]
ID:9 score 0.887628 (l,t,r,b)[429, 1339, 723, 1449]
ID:9 score 0.857632 (l,t,r,b)[1031, 1042, 1123, 1090]
ID:9 score 0.830450 (l,t,r,b)[1169, 1001, 1258, 1082]
ID:9 score 0.818386 (l,t,r,b)[5, 1080, 569, 1231]
ID:9 score 0.793356 (l,t,r,b)[753, 1012, 847, 1044]
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值