c++不用 boost 库,怎么切割字符串?

2018-08-08 19:21:24 +08:00
 wsds

不用 boost 库,最简单的方式, 怎么拿到 test123

test/test123
3323 次点击
所在节点    程序员
26 条回复
v2qwsdcv
2018-08-09 09:51:38 +08:00
araraloren
2018-08-09 11:08:48 +08:00
~~ 推荐 strtok 的都是什么心态。。
mingl0280
2018-08-09 12:50:04 +08:00
string s("test/test123");
int lastSlash = s.rfind('/');
if (lastSlash != s::npos)
string t = s.substr(lastSlash+1);

t 就是结果。
mingl0280
2018-08-09 12:50:52 +08:00
@agostop 基本不用 boost 路过
yazoox
2018-08-09 12:59:36 +08:00
也挺好奇的,现在 c++都用什么库?
裸的 c++用起来,真的老费劲了......
dychenyi
2018-08-09 14:02:59 +08:00
23 是最简单的写法。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/478040

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX