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[]=
{
    
2605, 2606, 2618, 2619,
    
2609, 2610, 2622, 2623,
    
2612, 2624, 2651, 2663,
    
2613, 2625, 2652, 2664,
    
1627, 1628,
    
1623, 1624, 1625, 1626,
    
48, 49, 50, 51, 52, 54, 55, 56, 1326, 1327, 1328, 1329,
    
53,
    
564, 565,
    
588, 589,
    
592, 593, 594, 595,
    
596, 597,
    
1616, 1617, 1618, 1619, 1621, 1659, 1660,
    
1620, 1657, 1662, 1663, 1664, 1665,
    
1630, 1631, 1635, 1649, 1650, 1651, 1652,
    
1634, 1653, 1654, 1655,
    
1647, 1648,
    
1666,
    
1667,
    
1668, 1669, 1672, 1673, 1674, 1675,
    
1670, 1671, 1676, 1677, 1678, 1679,
    
1163, 1164,
    
1711, 1712, 1713, 1714,
    
1715, 1716, 1717, 1718, 1743, 1744, 1745, 1746,
    
1719, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727,
    
1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742,
    
590, 591,
    
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 阅读(330) 评论(0)  编辑 收藏 引用 所属分类: C++ Zealot!