我想将两个整数值存储到C++中的char数组中。 这里是代码..存储和读取int数据到字符数组
char data[20];
*data = static_cast <char> (time_delay); //time_delay is of int type
*(data + sizeof(int)) = static_cast<char> (wakeup_code); //wakeup_code is of int type
现在上节目的另一端,我想改变这种操作。也就是说,从这个char数组中,我需要获取time_delay和wakeup_code的值。
我该怎么做?
感谢, 尼克
P.S:我知道这是做这种愚蠢的方式,但相信我,它的约束。
或'reinterpret_cast'如果您使用命名演员 – Dani
C风格演员不应该再用于C++了,特别是如果您不清楚可能的副作用。 – arne