operator<<(std::sub_match)
来自cppreference.com
| |
(C++11 起) | |
写入匹配子序列 m 的表示到输出流 os。
等价于 os << m.str()。
参数
| os | - | 要写入表示的输出流 |
| m | - | 要输出的子匹配对象 |
返回值
os
示例
运行此代码
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::string sentence{"Quick red fox jumped over a lazy hare."};
const std::regex re{"([A-z]+) ([a-z]+) ([a-z]+)"};
std::smatch words;
std::regex_search(sentence, words, re);
for (const auto& m : words)
// m 类型为 `const std::sub_match<std::string::const_iterator>&`
std::cout << '[' << m << "] ";
std::cout << '\n';
}
输出:
[Quick red fox] [Quick] [red] [fox]