Boost::string_ref find algorithms
Boost::string_ref find algorithms
我有一些问题弄清楚什么是boost库string_reffind函数做。我写了下面的程序
int main(int argc, char **argv) {
boost::string_ref ref = string("<a>n1234567n</a>n<a>");
cout << ref.find_first_of("<a>") << endl; // output 12
cout << ref.find("<a>") << endl; // output 17
}
我不明白为什么find给了我模式的最后一次出现,而find_last_of甚至根本没有意义!有人能帮帮我吗?
From the docs:
提振。StringRef是Jeffrey Yaskin的N3442的实现:string_ref: a 对字符串的非所属引用。
string_ref
不拥有任何东西,只是指代它。所以当你写:
boost::string_ref ref = string("<a>n1234567n</a>n<a>");
,临时string
在行尾被销毁,现在你有一个悬空引用。其他都是UB。
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 在 QVector<std::unique_ptr 上使用 std::find<Type>>
- 错误"Could not find Boost"(缺少:上下文标头)
- /usr/bin/ld: cannot find -lc++
- std::find,返回所有找到的值的替代方法,而不仅仅是存在重复的向量的第一个值
- 使用 find 解析文件会给出不同文件的奇怪结果
- 在 ifcondition al中 find() C++ STL 中的 == a.end() 有什么用?
- Cannot find -lglad
- "Cannot find -l<directory>"错误 - CMake
- 为什么在向量上使用 std::find() 时会出现错误?
- 为什么映射插入和 map.find() 的单次迭代比插入和 map.find() 的两次单独迭代慢得多
- C++ find() 在存储为变量时返回不同的值
- set::find 查找不存在的元素
- 使用 std::find 时没有匹配的函数调用错误
- 在先前调用 string::find 后添加内存分配和内存集会导致它返回 npos.为什么?
- Windows cannot find MinGW
- find() stl in vector in c++
- Boost::string_ref find algorithms