With
long int *x=new long int[1424];
You declare a pointer pointing to an array of 1424 long int. But with the reading
in.read((char*)x,1424);
You are reading 1424 bytes.
And in the loop you loop over the array, but add 4 to the index, so only every four element of x is pushed back.
You should first think about that may long is eight bytes on 64-bit machines. You also don't really need to allocate the array dynamically. And the array should contain 356 entries, just like when you wrote it to the file. You can then read sizeof(x) bytes in the call to read. And finally in the loop, you loop from 0 to sizeof(x) / sizeof(x[0]):
long int x[356];
ifstream in("h.h",ios::binary|ios::in);
in.read((char*) x, sizeof(x));
for(int y = 0; y < (sizeof(x) / sizeof(x[0])); y++)
{
}
If you want to read the contents as long int into a std::vector, there are actually a "simpler" way, using iterators and standard C++ algorithms:
std::vector<long int> e1;
std::ifstream in("h.h", std::ios::binary | std::ios::in);
std::copy_n(std::istream_iterator<long int>(in),
356,
std::back_inserter(e1));
The above statements declares a vector, opens a file, and copies 356 long int entries from the file into the vector e1.
For references, see std::istream_iterator, std::back_inserter, and of course std::copy_n.
The above C++ solution wasn't working, so I've experimented with another:
std::vector<long> v(356);
std::ifstream in("h.h", std::ios::binary);
std::for_each(std::begin(v), std::end(v), [&in](long& v) {
in.read(reinterpret_cast<char*>(&v), sizeof(v));
});
The above solution have been tested with this program, and it works for me.
What the above statements to, is create a vector containing 356 long entries, opens the file, and reads into the vector one entry at a time.
long intmay actually have different size than 4. Usesizeof(long int).