gpt4 book ai didi

c++ - 用/拆分 C++ 字符串

转载 作者:太空狗 更新时间:2023-10-29 23:23:24 26 4
gpt4 key购买 nike

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

最佳答案

使用 std::string 中的 findsubstr 方法。

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

关于c++ - 用/拆分 C++ 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11521914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com