posts - 14,comments - 2,trackbacks - 0
花了2个多小时终于完成了。
Note(int to string):e.g:

  ostringstream ss;
  ss << mappedCounterArray[i];
  string str = ss.str();
#include <iostream>
#include 
<string>
#include 
<fstream>
#include   
<sstream>  
using namespace std;

typedef 
bool BOOL;
const int MAX_OF_LINE = 100;
const int mappedCounterArray[]=
{
    
2605260626182619,
    
2609261026222623,
    
2612262426512663,
    
2613262526522664,
    
16271628,
    
1623162416251626,
    
48495051525455561326132713281329,
    
53,
    
564565,
    
588589,
    
592593594595,
    
596597,
    
1616161716181619162116591660,
    
162016571662166316641665,
    
1630163116351649165016511652,
    
1634165316541655,
    
16471648,
    
1666,
    
1667,
    
166816691672167316741675,
    
167016711676167716781679,
    
11631164,
    
1711171217131714,
    
17151716171717181743174417451746,
    
171917201721172217231724172517261727,
    
172817291730173117321733173417351736173717381739174017411742,
    
590591,
    
2728
}
;

BOOL isMappedCounter(
const string& counterIDStr)
{
    
int size = sizeof(mappedCounterArray)/sizeof(int);
    
int i=0;
    
while (i<size)
    
{
        ostringstream ss;
        ss 
<< mappedCounterArray[i];
        
string str = ss.str();
        str 
+= " ";
        str 
= " " + str;

        
if (counterIDStr.find(str)<counterIDStr.length())
            
return true;
        i
++;
    }

    
return false;
}


void setFile(void)
{
    ifstream in_file;
    in_file.open(
"./abc.txt");

    ofstream out_file;
    out_file.open(
"outFile.txt");

    
char ptr[MAX_OF_LINE];
    
for (int i=0; i<MAX_OF_LINE;i++)
        ptr[i]
='\0';
    
while(in_file.getline(ptr,MAX_OF_LINE))
    
{
        
string str=ptr;
        
if ((str.find("**id = ")<str.size()) && (!isMappedCounter(str)) )
            str
=str.substr(0,str.find("**id = "));
        out_file 
<< str << endl;
        cout 
<< str << endl;
    }

    in_file.close();
    out_file.close();
}


BOOL isSpaceOrTab(
const string& str)
{
    
char ch_space = ' ';
    
char ch_tab = '\b';
    size_t i
=0;
    
while (i<str.length())
    
{
        
if ((str[i] != ch_space) && (str[i] != ch_tab))
            
return false;
        i
++;
    }

    
return true;
}


void removeSpace(void)
{
    ifstream in_file;
    in_file.open(
"./outFile.txt");

    ofstream out_file;
    out_file.open(
"outFileWithNoSpace.txt");

    
char ptr[MAX_OF_LINE];
    
for (int i=0; i<MAX_OF_LINE;i++)
        ptr[i]
='\0';
    
while(in_file.getline(ptr,MAX_OF_LINE))
    
{
        
string str=ptr;
        out_file 
<< str << endl;
        cout 
<< str << endl;
        
        
while (isSpaceOrTab(str))
        
{
            in_file.getline(ptr,MAX_OF_LINE);
            str 
= ptr;
            
if (isSpaceOrTab(str))
                
continue;
            out_file 
<< str << endl;
            cout 
<< str << endl;
            
break;
        }

    }

    in_file.close();
    out_file.close();
}


int main()
{
    setFile();
    removeSpace();
    system(
"pause");
    
return 0;
}
posted on 2009-02-18 23:53 Jiggy.Stone 阅读(242) 评论(0)  编辑 收藏 引用 所属分类: C++ Zealot!

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理