名前空間
変種
操作

operator<<(std::sub_match)

From cppreference.com
< cpp‎ | regex‎ | sub match
 
 
 
正規表現ライブラリ
クラス
(C++11)
アルゴリズム
イテレータ
例外
Traits
定数
(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]
English 日本語 中文(简体) 中文(繁體)