C/C++截取下载url中文件名称

本文展示了一段C++代码,用于从URL字符串中提取最后一个斜杠后的部分,即文件名。示例代码中,使用了`find_last_of`函数找到路径中的最后一个'/',然后通过`substr`获取文件名。程序输出提取到的文件名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章目录


https://blog.youkuaiyun.com/u013171226/article/details/107680268

在这里插入图片描述

实例

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str_path = "https://cdn.stubdownloader.services.mozilla.com/builds/firefox-latest-ssl/zh-CN/win64/3fc87ab359974206b023c078da971146640e845508111e6526ebdec9c8d089e0/Firefox%20Setup%2091.0.exe";
    int pos = str_path.find_last_of("/");
    string filename(str_path.substr(pos+1));
	cout << "filename:" << filename << endl; 
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值