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

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

c++ - Insert record in binary data file

In C++ binary file handling what does the syntax (file.read((char *)&vg, sizeof(vg))) mean?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The first argument is casting the array "vg" to a char pointer. sizeof(vg) returns the size of the array in bytes. A C++ way to do this would be

std::array<int, 10> vg{};
file.read(static_cast<char*>(vg.begin()), vg.size());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...