Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

std::streampos size;
char * memblock;

std::ifstream input ("A.JPG", std::ios::in|std::ios::binary|std::ios::ate);

if (input.is_open())
{
    size = input.tellg();
    memblock = new char [size];
    input.seekg (0, std::ios::beg);
    input.read (memblock, size);
    input.close();

    std::cout << "[INPUT]the entire file content is in memory " << sizeof(memblock) << " 
";

}
delete[] memblock;

I would like to use the ifstream to read A.JPG (28KB) and save it into the array memblock. But why do the size of the memblock is 4 instead of 28403 while the variable size is equal to 28403?

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

Because memblock is a pointer, so the sizeof operator evaluates to the size of the pointer variable, which is 4 bytes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...