I am trying to make a function to read in a value, then convert it to little endian.
I wrote this:
But this is only working for int and the compiler won't accept trying to give it a float or double.
Should I scrap the template and just overload it?
I wrote this:
Code:
template<typename T>
void Read(T& value, std::ifstream& in) {
std::vector<unsigned char> bytes(sizeof(T));
in.read(reinterpret_cast<char*>(&bytes[0]), sizeof(T));
value = 0;
for(int i = 0; i < sizeof(T); i++) {
value |= (bytes[i] << i * 8);
}
}
Should I scrap the template and just overload it?
Comment