And*_*rew 9 c++ string algorithm boost
我正在尝试使用boost字符串算法进行不区分大小写的搜索.
总新手在这里.
如果我这样使用它,我会收到错误.
std::string str1("Hello world");
std::string str2("hello");
if ( boost::ifind_first(str1, str2) ) some code;
Run Code Online (Sandbox Code Playgroud)
转换为char指针可以解决问题.
boost::ifind_first( (char*)str1.c_str(), (char*)str2.c_str() );
Run Code Online (Sandbox Code Playgroud)
有没有办法直接搜索std :: string对象?
此外,也许还有另一种方法可以知道字符串是否存在于另一个字符串中,并且不区分大小写的搜索?
Fre*_*son 13
你需要使用boost :: iterator_range.这有效:
typedef const boost::iterator_range<std::string::const_iterator> StringRange;
std::string str1("Hello world");
std::string str2("hello");
if ( boost::ifind_first(
StringRange(str1.begin(), str1.end()),
StringRange(str2.begin(), str2.end()) ) )
std::cout << "Found!" << std::endl;
Run Code Online (Sandbox Code Playgroud)
编辑:在typedef中使用const iterator_range允许传递临时范围.
| 归档时间: |
|
| 查看次数: |
5032 次 |
| 最近记录: |