c++ - Cout Not Printing Contents of Pointed To Memory -
c++ - Cout Not Printing Contents of Pointed To Memory -
i have next code:
if (myfile.is_open()) { int = 0; while (myfile.good()) { char *ptr = &(reinterpret_cast<char*>(&mem[0]))[i]; myfile.read(ptr, sizeof(struct req)); cout << ptr << endl; += sizeof(struct req); } }
the cout in loop here seems print nothing, although know code setting memory because prints out right values if cout << mem[5]
instead. basically, want print contents of whatever ptr
referring to. silly question, know what's wrong here?
cout << ptr
, if ptr
of type char*
, treats ptr
pointer (the first character of) c-style string, , prints contents of string to, not including, terminating '\0'
null character.
if want print pointer value, convert void*
:
cout << (void*)ptr << ...
that's assuming actuallly want print value of pointer, appear hexadecimal memory address. title says "contents of pointer", memory address (the contents of pointer object itself). if instead want print info pointer points to, please update question create clearer want print , in format.
c++ memory cout
Comments
Post a Comment