it's turn out that the program cant compile. and when i change to this file.write(reinterpret_cast<char*>(*itr), sizeof(*itr));
its compiled but if i try to input a not-in-order list, the program crashs
i want to know what the problem is. thank
itr is an iterator, it represents a place in a file not a printable character. Casting it to a char pointer or casting it's value to a char pointer doesn't magically make it printable.
1 2 3 4 5
for (vector<int>::iterator itr = score.begin(); itr != score.end(); itr++)
{
int temp = *itr;
file.write(reinterpret_cast<char*>(&temp), sizeof(temp));
}
Here they are dereferencing the iterator and storing that value as an integer then on the next line they are casting the reference to that integer it to a char pointer.