Regular Expression Regular Expression -3 (C ++)

xiaoxiao2021-03-06  67

Finally, I used C , because STL has no regular expression, so I use Regex in Boost. But because it is not very familiar, the code is very foot, will look at it. Ha ha.

#include #include #include #include using namespace std; void readFile (const char * filename, string & str); void writeFile (const char * filename, const string Str); void filter (const string infut, string & output); int Main (int Argc, const char * argv [i if (argc <3) {cout << "please enter 2 filenames (eg in.txt out. TXT) "<< Endl; Return 1; String Strin, Strout; ReadFile (Argv [1], Strin); Filter (Strin, Strout); Writefile (Argv [2], strout);} void readfile (const char * FileName, String & Str) {ifstream in (filename); str.rase (); str.reserve (in .rdbuf () -> in_avail ()); string straTemp; while (! in.eof ()) {in >> STRTEMP; STR.APpend (Strtemp);} in.close ();} void writefile (const string str) {OFStream out (filename); out.write (str.c_str (), (streamsize) STR ()); out.flush (); out.close ();} V Oid filter (const string infut, string& output) {output.rase (); output.reserve (input.length ()); boost :: regex expression ("/" (// w ): (// w )% (// w )% // w ) / ""); boost :: smatch group; boost :: regex_constants :: match_flag_type flags = boost :: regex_constants :: match_default; string :: const_iterator start, end; start = input.begin (); end = Input.end (); while (boost :: regex_search (start, end, group, expression, flags) {output.append (group [1]); Output.Append ("::"); Output.Append (Group [ 2]); OUTPUT.APpend ("*"); Output.Append (Group [3]);

转载请注明原文地址:https://www.9cbs.com/read-110542.html

New Post(0)