vs2012 正则

来源:互联网 发布:手机计时器软件 编辑:程序博客网 时间:2024/05/21 17:31
#pragma warning(disable : 4996)
// std_tr1__regex__regex_replace.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
#include <cstdio>
#include<string>
#define FIND_CHAR "a"
#define REPLACE_CHAR "A"
#define FILE_SRE "F:\\CODE\\regex\\Debug\\13123.txt"
#define BUFF_SIZE 1024*1024*2
using namespace std;


int main() 

FILE * pfopen = 0,*pfsave;
pfopen = fopen(FILE_SRE,"r");
pfsave = fopen(string(string(FILE_SRE)+"re.txt").c_str(),"w");
char *buff;
int txt_size;
buff= new char[BUFF_SIZE];
txt_size=fread(buff,sizeof(char),BUFF_SIZE,pfopen);
*(buff + txt_size + 1) = '\0';
fclose(pfopen);
string fs;
fs.append(buff);
std::regex rx(FIND_CHAR); 
    std::string fmt(REPLACE_CHAR); 
    std::regex_constants::match_flag_type fonly = std::regex_constants::format_first_only;
string outs = std::regex_replace(fs, rx, fmt);
std::cout << "replacement == " << outs << std::endl;
outs.pop_back();
outs.push_back('\0');
fprintf(pfsave,"%s",outs.c_str());
fclose(pfsave);
delete buff;
    return 0; 
}
0 0