TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MARIO SEMO
from: KURT KUZBA
date: 1998-05-13 06:41:00
subject: What is CString 1/2

MS>   PS: what is CString? is it a typedef for char * ?
MS>   i assume typedef char CString. or what.
MS>   i can't see why the above code is compilable.
   CString is a class which allows string manipulation.
   Here is an example of a string class:
 //   begin   STRCLS.CPP   PUBLIC DOMAIN   ( part 1 of 2 )
#include 
#include 
#include 
#include 
class MyStrings
{
public:
   MyStrings(const char*);
   ~MyStrings();
   const char *String() { return szS; }
   void Precision(int iP) { dP = (iP  0) ? iP : 2; }
   void operator =(const char *szA) { Mak(szA); }
   void operator =(char);
   void operator =(short siA)          { *this = (long)siA; }
   void operator =(unsigned short siA) { *this = (long)siA; }
   void operator =(int iA)             { *this = (long)iA;  }
   void operator =(unsigned uA)        { *this = (long)uA;  }
   void operator =(long);
   void operator =(unsigned long);
   void operator =(double);
   void operator +(const char *szA) { Add(szA); }
   void operator +(char);
   void operator +(short siA)          { *this + (long)siA; }
   void operator +(unsigned short suA) { *this + (long)suA; }
   void operator +(int iA)             { *this + (long)iA;  }
   void operator +(unsigned uA)        { *this + (long)uA;  }
   void operator +(long);
   void operator +(unsigned long);
   void operator +(double);
   operator const char *() { return szS; }
private:
   void Add(const char*);
   void Mak(const char*);
   int iLen, dP;
   char *szS;
};
MyStrings::MyStrings(const char *szSt = NULL)
{
   szS = NULL;
   dP = 2;
   if(szSt && *szSt)
      *this = szSt;
}
MyStrings::~MyStrings()
{
   if(szS)
      delete []szS;
   dP = 2;
}
void MyStrings::Mak(const char *szA)
{
   char *temp = new char [(iLen = strlen(szA)) + 1];
   sprintf(temp, "%s", szA);
   if(szS)
      delete []szS;
   szS = temp;
}
void MyStrings::Add(const char *szA)
{
   char *temp = new char [(iLen += strlen(szA)) + 1];
   sprintf(temp, "%s%s", szS, szA);
   delete []szS;
   szS = temp;
}
 //   end   STRCLS.CPP   PUBLIC DOMAIN   ( part 1 of 2 )
> ] Love is not blind, but sometimes it looks the other way.....
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.