المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : CString Word Count and Word Search



C++ Programming
12-22-2009, 01:21 AM
I have been working on this problem for a long time and with no progress.
I am trying to count the number of words in a CString and other punctuation and specific word counts.
My code is working properly for .txt files using ifstream and stringstream.

However when I was trying to convert those codes from txt files to CString, errors came in such as conversion error between CString and Stringstream. Will appreciate if you can take a look at my codes and suggest a solution. Thanks a lot!

CString Content("some text inside");
string file,line,word,temp;
stringstream *ss;
map freq;
map::iterator z

stringstream myfile(Content);

while (! myfile.eof() )
{
// Line & Word Counts
while (getline (myfile,line)){
++lineCnt;
ss = new stringstream(Content);
while (ss->good()){
if ((*ss)>>word){
++dwordCnt;
if ((z=freq.find(word)) == freq.end()){
freq.insert(pair(word,1));
}else {
freq[word]++;
}
//Semi-colon Count
size_t p=0;
size_t n=0;
size_t m=0;
size_t j=0;
while ((p = word.find(';',p)) != string::npos){
++semiCnt; ++p;
}
while ((n = word.find('.',n)) != string::npos){
++stopCnt; ++n;
}
while ((m = word.find('?',m)) != string::npos){
++QueCnt; ++m;
}
while ((j = word.find('!',j)) != string::npos){
++exclCnt; ++j;
}
}
}
delete ss;
}
}

for (z = freq.begin();z != freq.end(); ++z) {
if (z->second == 1) ++duniqCnt;
if ((z->first).find(BUT) != string::npos) ++butCnt;
if ((z->first).find(AND) != string::npos) ++andCnt;
if ((z->first).find(HENCE) != string::npos) ++henceCnt;
if ((z->first).find(WHILE) != string::npos) ++whileCnt;
if ((z->first).find(BECAUSE) != string::npos) ++becauseCnt;
if ((z->first).find(AS) != string::npos) ++asCnt;
if ((z->first).find(SHALL) != string::npos) ++shallCnt;
if ((z->first).find(THE) != string::npos) ++theCnt;
if ((z->first).find(OF) != string::npos) ++ofCnt;
}