関数の変数を主なスコープに渡したいと思います。私はCで行うのと同じようにしようとしていますが、何も返しません。関数から "main"スコープに変数(配列型)を渡します。型:std :: tr1 :: match_results <std :: string :: const_iterator>
私はコンパイルして実行すると、出力が出力できると関数の戻り
#include "StdAfx.h"
#include <regex>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
std::tr1::match_results<std::string::const_iterator> match(std::string& regex, const std::string& ip,std::tr1::match_results<std::string::const_iterator> res)
{
const std::tr1::regex pattern(regex.c_str());
bool valid = std::tr1::regex_match(ip, res, pattern);
std::cout << ip << " \t: " << (valid ? "valid" : "invalid") << std::endl;
cout << "FIRST RES FOUND: " << res[1] << endl;
return res;
}
int main()
{
string regex = "(\\d{1,3}):(\\d{1,3}):(\\d{1,3}):(\\d{1,3})";
string ip = "49:22:33:444";
std::tr1::match_results<std::string::const_iterator> res;
match(regex,ip.c_str(), res);
cout << "Result >" << res[1] << "< " << endl;
_getch(); return 0;
}
後にそれに対処したい:「最初に見つかったRES:49 結果> <」
それはおそらく、本当にシンプルなソリューションですが、何を、私は私のメインは、のようにそれを正しく読むことができるためにそれを設定しなければならない。事前に「結果> 49 <」
感謝を。 :)