Wac*_*cek 163
我会用比较方法:
std::string s("xyzblahblah");
std::string t("xyz")
if (s.compare(0, t.length(), t) == 0)
{
// ok
}
Neu*_*ino 13
一种可能更符合标准库精神的方法是定义自己的begin_with算法.
#include <algorithm>
using namespace std;
template<class TContainer>
bool begins_with(const TContainer& input, const TContainer& match)
{
    return input.size() >= match.size()
        && equal(match.begin(), match.end(), input.begin());
}
这为客户端代码提供了更简单的接口,并与大多数标准库容器兼容.
Ale*_*Ott 10
查看Boost的String Algo库,它具有许多有用的功能,例如starts_with,istart_with(不区分大小写)等.如果您只想在项目中使用部分boost库,那么您可以使用bcp实用程序来复制只需要文件
| 归档时间: | 
 | 
| 查看次数: | 65832 次 | 
| 最近记录: |