如果我需要從ifstream的投INT的地址正確的方式來字符指針
int myInt = 0;
fileStream.read(reinterpret_cast<char*>(&myInt), sizeof(int));
讀INT使用reinterpret_cast<char*>
正確的方式來實現這一目標?
如果我需要從ifstream的投INT的地址正確的方式來字符指針
int myInt = 0;
fileStream.read(reinterpret_cast<char*>(&myInt), sizeof(int));
讀INT使用reinterpret_cast<char*>
正確的方式來實現這一目標?
正在使用reinterpret_cast正確的方式來完成該操作嗎?
是的。更喜歡C++風格的轉換,而不是c風格轉換。
正如意見提出,用更好的方式read method function是:
int myInt = 0;
fileStream.read(reinterpret_cast<char*>(&myInt), sizeof(myInt));
這可能是幫助:http://stackoverflow.com/questions/4748232/reinterpret-cast :) – 2011-12-20 13:48:41
考慮使用'sizeof myInt'不能重複類型,並且如果稍後決定將類型更改爲eg,則是安全的'長'可能是一個不同的大小。 – unwind 2011-12-20 13:49:01
謝謝。聽起來像是一個好主意'sizeof myInt' – dextrey 2011-12-20 13:55:09