名稱空間
變體
操作

operator<<(std::sub_match)

來自 cppreference.com
< 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 );
(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 has type `const std::sub_match<std::string::const_iterator>&`
        std::cout << '[' << m << "] ";
    std::cout << '\n';
}

輸出

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