operator<<(std::sub_match)
From cppreference.com
| template< class CharT, class Traits, class BidirIt > std::basic_ostream<CharT,Traits>& |
(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]