class CWord : public CString
{
public:
CWord();
virtual ~CWord();
// CWord(const CString &stringSrc);
CString ParseNChar(unsigned int iChars);
CString SubWord(int iStartWord, int iNextNWords=0);
void ChangeDelimiterList(CString sList);
CString Word(int word);
const CString& operator=(const CString &stringSrc);
private:
CString m_sDelimiterList;
};
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWord::CWord()
{
m_sDelimiterList=" ";
}
CWord::~CWord()
{
}
//CWord::CWord(const CString & stringSrc)
//{
// CString::CString(stringSrc);
//}
const CString& CWord::operator =(const CString & stringSrc)
{
CString::operator=(stringSrc);
return *this;
}
CString CWord::Word(int word)
{
char *pChar=_strdup(GetBuffer(GetLength()));
CString sRet;
ReleaseBuffer();
if(word>=1)
{
pChar=strtok(pChar, m_sDelimiterList);
if(word==1)
{
sRet=pChar;
free(pChar);
return sRet;
}
else
{
for(int i=0;i<word-1;i++)
{
pChar=strtok(NULL, m_sDelimiterList);
}
return pChar;
}
}
else
{
return "";
}
}
void CWord::ChangeDelimiterList(CString sList)
{
m_sDelimiterList=sList;
}
CString CWord::SubWord(int iStartWord, int iNextNWords)
{
char*pChar=_strdup(GetBuffer(GetLength()));
int iWord=0;
CString sRet;
ReleaseBuffer();
if((iStartWord<1)||(pChar==NULL))
return "";
pChar=strtok(pChar, m_sDelimiterList);
iWord++;
while(iStartWord!=iWord)
{
pChar=strtok(NULL, m_sDelimiterList);
iWord++;
}
sRet=pChar;
iNextNWords--;
while((iNextNWords!=0)&&(pChar=strtok(NULL, m_sDelimiterList)))
{
// pChar=strtok(NULL, m_sDelimiterList);
if(pChar!=NULL)
{
sRet+=" ";
sRet+=pChar;
}
iNextNWords--;
}
return sRet;
}
CString CWord::ParseNChar(unsigned int iChars)
{
char *pChar=_strdup(GetBuffer(GetLength()));
CString sRet;
ReleaseBuffer();
for(unsigned int i=0;i<iChars;i++)
{
sRet+=pChar[i];
}
_mbsnbset((unsigned char *)pChar, ' ', iChars);
CString::operator=(pChar);
TrimLeft();
return sRet;
}
Everything compiles fine (should do what I want right!):) but the indicated line below fails to put the CString into the CWord.
CFlexCheckDoc* pDoc = GetDocument();
CString sTemp=pDoc->m_sFlexData;
CString sTTemp;
--> CWord wWord=sTemp;
When I make the change as follows the assignment works fine
CFlexCheckDoc* pDoc = GetDocument();
CString sTemp=pDoc->m_sFlexData;
CString sTTemp;
CWord wWord;
wWord=sTemp;
I am looking for some one who can break it down for me why this is happening. You know not repeat the same mistake.
Thanks Guys.
CWord::CWord(const CString& rhs) :
CString(rhs)
{
// Nothing needed here
}
Notice the colon (:), which when used in the constructor signifies the beginning of the initialization list. For more information about initializing base classes, read about it in any C++ book.