Why don't you declare a
as char*
instead, like this:
//int *a = new int[100];
char *a = new char[100];
iFile.read(a, 100 );
No casting required now.
EDIT:
Okay, I read your comment and the commented line in your post. In that case:
iFile.read(reinterpret_cast<char*>(a), sizeof(int)*100);
should suffice.
However,I personally would choose C-style cast:
iFile.read((char*)a, sizeof(int)*100);
That is because I don't see any danger here. Everything seems fine even with C-Style cast!
Best yet less tedious cast
Define this function template:
template<class To, class From>
To any_cast(From v)
{
return static_cast<To>(static_cast<void*>(v));
}
Then use it:
//`From` type will be inferred from the function argument. :-)
iFile.read(any_cast<char*>(a), sizeof(int)*100);
Looks good?
I think this any_cast
can be used to cast from any-type to any-type!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…