Re: [問題] boost regex sub-expression

看板C_and_CPP作者 (克里斯)時間15年前 (2009/04/12 19:23), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
您試用看看吧 vc2008 sp1 tr1裡面的regex 據說是 boost 來的 #include <iostream> #include <string> #include <regex> using namespace std; using namespace std::tr1; int main(int argc, char* argv[]) { string ss("xyz1 xyz2 xyz3 xyz4"); regex rx("((xyz)(\\d))"); /*------------------------------------------------------------*/ cout << "sregex_token_iterator" << endl; sregex_token_iterator itrBegin2(ss.begin(), ss.end(), rx), itrEnd2; copy(itrBegin2, itrEnd2, ostream_iterator<string>(cout, "\n")); cout << endl; /*------------------------------------------------------------*/ cout << "sregex_iterator" << endl; sregex_iterator itrBegin(ss.begin(), ss.end(), rx), itrEnd; for (sregex_iterator itr = itrBegin; itr != itrEnd; ++itr) { for (unsigned int cou = 0; cou < itr->size(); ++cou) { cout << itr->str(cou) << ","; } cout << endl; } system("pause"); return 0; }/* sregex_token_iterator xyz1 xyz2 xyz3 xyz4 sregex_iterator xyz1,xyz1,xyz,1, xyz2,xyz2,xyz,2, xyz3,xyz3,xyz,3, xyz4,xyz4,xyz,4, */ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.195.88.23

04/12 20:36, , 1F
感謝
04/12 20:36, 1F
文章代碼(AID): #19uSyXRy (C_and_CPP)
文章代碼(AID): #19uSyXRy (C_and_CPP)