命名空间
变体
操作

operator<<(std::sub_match)

来自 cppreference.cn
< cpp‎ | regex‎ | sub match
 
 
 
正则表达式库
(C++11)
算法
迭代器
异常
特性
常量
(C++11)
正则表达式语法
 
 
template< class CharT, class Traits, class BidirIt >

std::basic_ostream<CharT,Traits>&

    operator<<( std::basic_ostream<CharT,Traits>& os, const sub_match<BidirIt>& m );
(since C++11)

将匹配的子序列 m 的表示形式写入到输出流 os。等效于 os << m.str()

[edit] 参数

os - 要将表示形式写入的输出流
m - 要输出的 sub-match 对象

[edit] 返回值

os

[edit] 示例

#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 has type `const std::sub_match<std::string::const_iterator>&`
        std::cout << '[' << m << "] ";
    std::cout << '\n';
}

输出

[Quick red fox] [Quick] [red] [fox]