C++ C++;在'之前应为初始值设定项/=';代币
我犯了一个错误C++ C++;在'之前应为初始值设定项/=';代币,c++,C++,我犯了一个错误 expected initializer befor '/=' token. 我有 const unsigned in array[] 在我的循环中,我有: for (int i = 0; i< length; i++) { while (array[i] > 0) { const unsigned int array[i] /= 10; } } for(int i=0;i0) { 常量无符号整数数组[i]/=10
expected initializer befor '/=' token.
我有
const unsigned in array[]
在我的循环中,我有:
for (int i = 0; i< length; i++)
{
while (array[i] > 0)
{
const unsigned int array[i] /= 10;
}
}
for(int i=0;i0)
{
常量无符号整数数组[i]/=10;
}
}
我怎样才能修好它?谢谢
常量无符号整数数组[i]/=10代码>
应该是:
数组[i]/=10代码>
如果在变量名之前写入类型,则执行变量声明。但是,这不是您的意图,您只是想访问它。我怀疑您打算将每个数组条目除以10。我还假设您给了数组一个大小(在括号中)。我还假设length
是正确的
但仍然存在多个错误
首先,应该定义数组unsigned int
,而不是const unsigned in
(删除const并修复输入错误),否则无法修改它
然后删除循环中的类型声明,并使用array[i]/=10
而不是常量无符号整数数组[i]/=10代码>
此外,我想知道为什么要尝试使用两个嵌套循环?只需完全删除while循环:
for (int i=0; i<length; i++)
{
array[i] /= 10;
}
for(inti=0;i我认为您需要对这两个数组以及更一般的C进行一些了解。
当您用“const”声明变量时,它将其声明为常量,因此以后不能更改
const unsigned int array[]
for (int i = 0; i < length; i++)
{
while (array[i] > 0)
{
const unsigned int array[i] /= 10;
}
}
const无符号整数数组[]
for(int i=0;i0)
{
常量无符号整数数组[i]/=10;
}
}
应改为
unsigned int array[];
for (int i = 0; i < length; i++)
{
if (array[i] > 0)
{
// If array[i] is greater than zero, divide it by 10
array[i] /= 10;
}
}
无符号整数数组[];
for(int i=0;i0)
{
//如果数组[i]大于零,则将其除以10
数组[i]/=10;
}
}
好的,这是广泛的错误修复请检查这些链接:
谢谢。您错过了错误消息中的输入错误。他也应该修复它!