operator<<(std::sub_match)
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]
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/regex/sub_match/operator_ltlt