Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need confirmation on CFile::Write()

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
I have a pointer:

char *SomeCharPointer = new char[10];

Lets say I want to write to a file:

CFile SomeFile("C:\\bla.txt", CFile::modeWrite|CFile::modeCreate);

SomeFile.Write(SomeCharPointer, sizeof(SomeCharPointer));

Now, when I do this, I only get the first 4 characters...but when I do this:

SomeFile.Write(SomeCharPointer, strlen(SomeCharPointer));

I get all 10 chars. I'm guessing it's because if this:

Since SomeCharPointer is a pointer, its actual size is 32 bytes (mem location), so therefore, only 4 chars get written (4 chars x 8 bytes a piece = 32 bytes). But when I do strlen(), it returns the actual length...or 10, this is why I get all 10 chars. Is this logic correct, or am I totally off. Thanks in advance!

Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
 
What you guessed is correct. sizeof(SomeCharPointer)is the size of SomeCharPointer pointer (4 bytes) because you defined it as a pointer.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top