my program kept crashing for some reason and i narrowed it down to the following code (i know it has something to do with the pointer):
the cout.write function always returns a bunch of random garbage when its meant to return 'AAAAAA....', also im not 100% sure if the size im using is right.Code:struct _cTemp { unsigned int nSize; char *sData; }; int main() { _cTemp cTemp; cTemp.nSize = 0x41414141; // set uint to 'AAAA' cout << sizeof(_cTemp) << endl; cTemp.sData = new char [100]; memset(cTemp.sData, 'A', 100); // set char array to A's cout << sizeof(_cTemp) + 100 << endl; cout.write((char *)&cTemp, sizeof(_cTemp) + 100); cout << endl; delete[] cTemp.sData; return 0; }
i know the sizeof(_cTemp) = 8 (uint+pointer), when i assign the pointer 100 chars, would the size be 108? (im assuming that the size of the pointer doesnt change?).
anyway, why isnt it displaying 'AAAA..'? it shows the first 4 A's for the uint but not for the char array.