Warning:
warning C4244: 'initializing' : conversion from 'std::streamoff' to 'unsigned int', possible loss of data
Caused by:
unsigned int FileSize = File.tellg( ); // WARNING
std::cout << "Size = " << FileSize << std::endl;
Possible solution? Is it okay to do this:
// No more warnings but, is it safe?
unsigned int FileSize = (unsigned int)File.tellg( ); // OK?
std::cout << "Size = " << FileSize << std::endl;
How about this?
// No more warnings but, is it safe?
unsigned int FileSize = static_cast< unsigned int >( File.tellg( ) );
streamoff
is a signed integral type defined by your C++ standard library implementation, and large enough to cater for the largest possible file sizes. In my x86_64 stdlibc++ for example, it is a int64_t
.
In order to avoid potential data loss, use a larger type or... simply let your variable be of type streamoff
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With