场景
实现代码
初始化是不正确的,因为需要转义反斜杠:
string filename = "C:\\MyDirectory\\MyFile.bat";
如果存在,则提取目录:
string directory;
const size_t last_slash_idx = filename.rfind('\\');
if (std::string::npos != last_slash_idx)
{
directory = filename.substr(0, last_slash_idx);
}
原文地址:https://www.cnblogs.com/17bdw/p/10356625.html
时间: 2024-11-08 23:44:55