最終更新日時(UTC):
が更新

履歴 編集

function template
<regex>

std::operator<< (非メンバ関数)(C++11)

namespace std {
  template <class charT, class ST, class BiIter>
  std::basic_ostream<charT, ST>& operator<<(
    std::basic_ostream<charT, ST>& os,
    const sub_match<BiIter>& m);
}

概要

ストリームへの出力を行う。

戻り値

os << m.str()

備考

テンプレート引数は 3 つあるが、規格上は文字列の出力に使用している operator<<charT = iterator_traits<BiIter>::value_type、かつ、ST = char_traits<charT> のバージョンしか存在しない。

#include <iostream>
#include <regex>
#include <string>

int main()
{
  const char ca[] = " abc ";
  const std::regex re(R"(\w+)");

  std::cmatch m;
  if (std::regex_search(ca, m, re)) {
    std::csub_match sub = m[0];
    std::cout << '\'' << sub << '\'' << std::endl;
  } else {
    std::cout << "not match" << std::endl;
  }
}

出力

'abc'

バージョン

言語

  • C++11

処理系