我想通过移位将一个unsignedchar存储到一个char中。由于这两种数据类型具有相同的长度(在我的机器上为1个字节),我希望以下代码能够工作:#include#include#includeusingnamespacestd;intmain(){printf("%d\n",sizeof(char));printf("%d\n",sizeof(unsignedchar));unsignedchartest=49;chartestchar=(char)(test-127);printf("%x\n",testchar);return0;}但事实并非如此。特别是,我得到了以下输出:11
我正在使用C++为游戏创建瓦片map。我的问题是,我想在Map构造函数中填充一个多维整数数组,但它无法正常工作。这是我在“Map.h”中的代码(不相关的代码已被删除)。classMap{private:intmapArray[15][20];};还有我来自Map.cpp的代码Map::Map(){mapArray={{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},{20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39},{40,41,42,43,44,45,46,4