私は次のようなC++の文字列を持っています:"dirname/filename.ini"
。の後にすべてを取得する必要があります/
。
これどうやってするの?
7291 次
3 に答える
12
の使用find
とsubstr
メソッドstd::string
。
std::string fullpath = "dirname/filename.ini";
int beginIdx = fullpath.rfind('/');
std::string filename = fullpath.substr(beginIdx + 1);
于 2012-07-17T11:53:06.180 に答える
9
Luchianによる回答を拡張するには、パスに円記号または円記号を含めることができる場合は、次を使用しますstd::string::find_last_of()
。
const int idx = fullpath.find_last_of("\\/");
if (std::string::npos != idx)
{
std::string filename(fullpath.substr(idx + 1);
}
于 2012-07-17T11:59:26.963 に答える