Surfer
asked on
CStringArray and CString deallocation??
How do I deallocate the memory for the following code?
CStringArray ob ;
CString s ;
CString *pStr ;
ob.SetSize( 0,100 );
for (INT ni=0;ni< 3/*1000*/;++ni) {
pStr = new CString ;
pStr->Format("Test String %d",ni) ;
ob.Add ( pStr->GetBuffer(0) );
pStr->ReleaseBuffer(-1 ) ;
}
CString s1 ;
s1 = ob.GetAt(1) ;
I tried:
for (INT n=0;n<3;++n)
delete (CString*) ob.GetAt(n) ;
and
delete ob.GetAt(n) ;
but the compiler complains.
CStringArray ob ;
CString s ;
CString *pStr ;
ob.SetSize( 0,100 );
for (INT ni=0;ni< 3/*1000*/;++ni) {
pStr = new CString ;
pStr->Format("Test String %d",ni) ;
ob.Add ( pStr->GetBuffer(0) );
pStr->ReleaseBuffer(-1 ) ;
}
CString s1 ;
s1 = ob.GetAt(1) ;
I tried:
for (INT n=0;n<3;++n)
delete (CString*) ob.GetAt(n) ;
and
delete ob.GetAt(n) ;
but the compiler complains.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER