Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator<<(std::sub_match)

      From cppreference.com
      <cpp‎ |regex‎ |sub match
       
       
       
      Regular expressions library
      Classes
      (C++11)
      Algorithms
      Iterators
      Exceptions
      Traits
      Constants
      (C++11)
      Regex Grammar
       
       
      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)

      Writes the representation of the matched subsequencem to the output streamos. Equivalent toos<< m.str().

      [edit]Parameters

      os - output stream to write the representation to
      m - a sub-match object to output

      [edit]Return value

      os

      [edit]Example

      Run this code
      #include <iostream>#include <regex>#include <string> int main(){std::string sentence{"Quick red fox jumped over a lazy hare."};conststd::regex re{"([A-z]+) ([a-z]+) ([a-z]+)"};std::smatch words;std::regex_search(sentence, words, re);for(constauto& m: words)// m has type `const std::sub_match<std::string::const_iterator>&`std::cout<<'['<< m<<"] ";std::cout<<'\n';}

      Output:

      [Quick red fox] [Quick] [red] [fox]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/regex/sub_match/operator_ltlt&oldid=178383"

      [8]ページ先頭

      ©2009-2026 Movatter.jp