如果我有char*数组:
char* c = getBytesFromSomewhere();我想将最后4个字节读入uint,然后再读前4个字节等等。我尝试了如下:
char* end = &c[size-5];若要获取指向数组中最后4个字节的指针,然后:
unsigned int n = *(reinterpret_cast<int *>(end));但它似乎不起作用..。我做错什么了?
发布于 2014-07-25 21:38:47
在下面的代码中,我这样做:
char* end = (c + strlen(c) - 5);
unsigned int tst = 0;
tst = c[0];
tst = ((tst << 8) | c[1]);
tst = ((tst << 8) | c[2]);
tst = ((tst << 8) | c[3]);https://stackoverflow.com/questions/24964687
复制相似问题