湖濱散記部落格的樹心幽徑[login][主頁]
538:20191123用DEV-C++設計可輸入拆碼來搜尋Boshiamy.cin文字檔的程式readbosh.cpp

20191123用DEV-C++設計可輸入拆碼來搜尋Boshiamy.cin文字檔的程式readbosh.cpp

REF 1:#C++11:正規表達式(Regular Expression)的使用

REF2 : 讓Dev C++支援C++11

REF3 :http://rocksaying.tw/archives/3866523.html

REF4: http://tommyjswu-blog.logdown.com/posts/726230-cpp11-regex-expression

 

(1)程式碼:readbosh.cpp

#include <fstream>
#include <iostream>
#include <regex>
using namespace std;

int main(){
  FILE *infile;
  infile = fopen("ansiBoshiamy.cin", "r");
   
  string input;
  printf("請輸入要查的字串:");
  getline(cin, input);
  string s1= input + " (.*)(\\n)";
 
  regex reg(s1,regex_constants::icase);

  char ln[100];
  int c=0;
  while (!feof(infile)) {
      fgets (ln , 100 , infile);
    if( regex_match(ln, reg) ){
        cout << " 找到匹配" <<" c=" << c++ << ":"<< ln  << endl;
      }
   }
  fclose(infile);
  return 0;
}

 

(2)執行結果:

請輸入要查的字串:aaa
 找到匹配 c=0:aaa 鑫

 找到匹配 c=1:aaa 龘

 找到匹配 c=2:aaa 鑆


--------------------------------
Process exited after 3.438 seconds with return value 0
請按任意鍵繼續 . . .


 


select id,article_id,topic,text from lt_articles_text where article_id =538; ok. update lt_articles set num_reads=num_reads +1 where id=538; ok.