用/分割C ++字符串 [英] Splitting a C++ String with /

查看:62
本文介绍了用/分割C ++字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++中有一个这样的字符串:"dirname/filename.ini" .我需要在/之后获取所有内容.
我该怎么办?

I have a string in C++ like this: "dirname/filename.ini". I need to get everything after the /.
How can I do this?

推荐答案

使用 std :: string 中的 find substr 方法./p>

Using find and substr methods from std::string.

std::string fullpath = "dirname/filename.ini";
int beginIdx = fullpath.rfind('/');
std::string filename = fullpath.substr(beginIdx + 1);

这篇关于用/分割C ++字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆