vector<vector<int>> mapVector(maxX, vector<int>(maxY));
char* mapBuffer = new char[mapString.size() + 1];
...
mapVector[i][j] = mapBuffer[y];
...
mapBuffer[i][j]
包含"#"符号,但在"mapVector[i][j] = mapBuffer[y]
"之后 mapVector[i][j]
contans 编号"35"。为什么它传递的是id而不是符号?
以下是使用 printf 查看数据的方法:
#include <stdio.h>
int main (int argc, char **argv){
char test='#';
printf("test %c %dn", test,test);
return 0;
}
%c 呈现为字符%d 呈现为 int
(以上是C语言,但C的那部分将由C++编译器编译)
因此,在您的代码中,如果您将向量更改为 char 向量,您将不会遇到问题:
vector<vector<char>> mapVector(maxX, vector<char>(maxY));
char* mapBuffer = new char[mapString.size() + 1];
...
mapVector[i][j] = mapBuffer[y];
...