如何将 char a[0] 转换为 int b[0],其中 b 是动态分配的空 int 数组
我试过了
char a[] = "4x^0";
int *b;
b = new int[10];
char temp = a[0];
int temp2 = temp - 0;
b[0] = temp2;
我想要 4 但它给了我 ascii 值 52
也在做
a[0] = atoi(temp);
给我 错误:从“char”到“const char*”的无效转换 初始化“int atoi(const char*)”的参数 1
最佳答案
你需要做的:
int temp2 = temp - '0';
相反。
关于c++ - 将单个字符转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1800875/