代码如下:
string path = "012/456789/2021-01-18"; //待操作的字符串
int pos = path.rfind('/'); // rfind(),从后向前找到'/'第一次出现的位置
cout << "pos is :" << pos << endl; // 打印‘/’的位置
if (pos != string::npos)
{
string path_2 = path.substr(pos + 1); // 从下一个位置开始截取
cout << path_2.c_str() << endl; // 打印日期
}
我的疑惑:
pos是int类型,string::npos又是字符串a是否包含b的含义
针对 代码中写的这一行判断 if (pos != string::npos);我有点不是很理解为什么这样写,希望有人能够解答一下