C++ r(自动匹配器=regexIterator;匹配器!=std::sregex_迭代器{};++matchItor) { std::smatch match{*matchItor}; mdy.push_back(match.str()); } const s

C++ r(自动匹配器=regexIterator;匹配器!=std::sregex_迭代器{};++matchItor) { std::smatch match{*matchItor}; mdy.push_back(match.str()); } const s,c++,arrays,C++,Arrays,r(自动匹配器=regexIterator;匹配器!=std::sregex_迭代器{};++matchItor) { std::smatch match{*matchItor}; mdy.push_back(match.str()); } const std::size_t mdySize{mdy.size()}; 对于(std::size\u t matchIndex{0};matchIndex“\n”和仅数字输入。 int dateArray[3]; for (int i=0; i<

r(自动匹配器=regexIterator;匹配器!=std::sregex_迭代器{};++matchItor) { std::smatch match{*matchItor}; mdy.push_back(match.str()); } const std::size_t mdySize{mdy.size()}; 对于(std::size\u t matchIndex{0};matchIndex如果(matchIndex!=mdySize&&matchIndex!=0)std::cout我该如何在这个上下文中使用它?链接引用中给出的示例没有帮助吗?只使用
'/'
而不是
'\n'
并且只使用数字输入。但是我该如何在这个上下文中使用它?链接引用帮助中给出的示例没有帮助吗?只使用
'/'
而不是
'\n'
只有数字输入。我如何在这个上下文中使用它?链接引用中给出的示例是否有帮助?只需使用
'/'
而不是
'\n'
并且只使用数字输入。但是,我如何在这个上下文中使用它?链接引用帮助中给出的示例是否没有帮助?只需使用
'/'
而不是
>“\n”
和仅数字输入。
int dateArray[3];
for (int i=0; i<3; i++)
    cin >> dateArray[i];
int month = dateArray[0];
...etc
if (((std::cin >> month).ignore() >> year).ignore() >> day) {
    // do something with the date
}
else {
    // deal with input errors
}
std::istream& slash(std::istream& in) {
    if ((in >> std::ws).peek() != '/') {
        in.setstate(std::ios_base::failbit);
    }
    else {
        in.ignore();
    }
    return in;
}

// ....
if (std::cin >> month >> slash >> year >> slash >> day) {
    // ...
}
#include <iostream>
#include <iterator>
#include <regex>
#include <string>


int main()
{
  std::string string{ "12/34/5678" };
  std::regex regex{ R"((\d{2})/(\d{2})/(\d{4}))" };

  auto regexIterator = std::sregex_iterator( std::begin( string ), std::end( string ), regex );

  std::vector< std::string > mdy;
  for( auto matchItor = regexIterator; matchItor != std::sregex_iterator{}; ++matchItor )
  {
    std::smatch match{ *matchItor };
    mdy.push_back( match.str() );
  }

  const std::size_t mdySize{ mdy.size() };
  for( std::size_t matchIndex{ 0 }; matchIndex < mdySize; ++matchIndex )
  {
    if( matchIndex != mdySize && matchIndex != 0 ) std::cout << '/';
    std::cout << mdy.at( matchIndex );
  }
}