// readtxt.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include<fstream>
#include <iostream>
#include <vector>
std::vector<tstring> m_vSave;
using namespace std;
tstring getline(FILE *stream)
{
tstring strRet;
TCHAR line[100] = {0};
while( _fgetts( line, 100, stream ) != NULL)
{
if (line[0] == 0xFEFF)//unicode 文件的头
{
strRet += &line[1];
}
else
{
strRet += line;
}
if (line[_tcslen(line)-1] == _T('\n'))
{
break;
}
}
return strRet;
}
void Trim( tstring& str , const tstring& chars =_T(" \t" ))
{
str.erase(str.find_last_not_of(chars)+1);
str.erase(0, str.find_first_not_of(chars));
}
int main(int argc,char **argv)
{
FILE *stream = NULL;
FILE *streamOut = NULL;
if( _wfopen_s( &stream,_T("E:\\1.txt"), _T("rt+,ccs=UNICODE ") ) == 0 )
{
tstring sRead;
while (!feof(stream))
{
sRead = getline(stream);
if (sRead.empty())
{
continue;
}
else
{
int n;
n=sRead.find(_T("="));
tstring s1 = _T("");
tstring s2 = _T("");
s1=sRead.substr(0,n);
s2=sRead.substr(n+1,sRead.length());
Trim(s1);
Trim(s2);
TCHAR tstrInitial[200]={0};
TCHAR tstrChinese[200]={0};
TCHAR tstrEspecial[200]={0};
bool flag = false;
_tcscpy(tstrInitial ,s2.c_str());
int j =0;
for(int i=0; i<s2.length(); i++)
{
if ((tstrInitial[i]>=0x4E00)&&(tstrInitial[i]<=0x9FA5))
{
tstrChinese[j] = tstrInitial[i] ;
/*tstrChinese[++j] = tstrInitial[++i];*/
j++;
flag = true;
}
else
{
if (flag==true)
{
break;
}
else
{
;
}
}
}
tstrChinese;
tstring data =_T("");
data+= s1;
data+=_T("=");
data+=tstrChinese;
data+=_T("\n");
m_vSave.push_back(data);
}
}
}
if( _wfopen_s( &streamOut,_T("E:\\2.txt"), _T("wt,ccs=UNICODE ") ) == 0 )
{
for(int k=0;k<m_vSave.size();k++)
{
fputws(m_vSave[k].c_str(),streamOut);
}
}
return 0;
}