Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
StringGrid c和x2B中的输出矩阵元素+;建设者_C_Arrays_Matrix_C++builder - Fatal编程技术网

StringGrid c和x2B中的输出矩阵元素+;建设者

StringGrid c和x2B中的输出矩阵元素+;建设者,c,arrays,matrix,c++builder,C,Arrays,Matrix,C++builder,我想创建一个数组并在StringGrid中输出它的元素,但我得到了一个错误 [C++错误]Unit1.cpp(31):E2034无法将“ansisting”转换为“int” 这是我的密码。你能说出是什么导致了错误吗 #define K 4 int M[K][K]; TForm1 *Form1; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } void __fastcall TForm1::B

我想创建一个数组并在StringGrid中输出它的元素,但我得到了一个错误

[C++错误]Unit1.cpp(31):E2034无法将“ansisting”转换为“int”

这是我的密码。你能说出是什么导致了错误吗

#define K 4

int M[K][K];


TForm1 *Form1;

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
         int i, j;
         for(i=0;i<K;i++)
         for(j=0;j<K;j++){
                M[i][j] = random(100);
                M[i][j]=StringGrid1->Cells[i][j];

         }
}
#定义k4
int M[K][K];
TForm1*Form1;
__fastcall TForm1::TForm1(TComponent*Owner)
:t表格(所有者)
{
}
void\uu fastcall TForm1::Button1Click(TObject*发送方)
{
int i,j;

对于(i=0;iCells[i][j]);
M[i][j]=StringGrid1->Cells[i][j].ToInt();
当我按下我的按钮1时,我收到另一个错误。它说:带有消息“”的EConvertError不是有效的整数值

问题在这里:
M[i][j]=StringGrid1->Cells[i][j];


StringGrid1->Cells是一个二维平移数组,M是一个二维整数数组。所以你不能直接将元素从一个元素移动到另一个元素:你必须先将它们转换为整数。

但是如果我写
strotint(StringGrid1->Cells[I][j]);
StringGrid1->Cells[I][j].ToInt;
当我按下我的按钮1时,我得到一个错误。上面写着:EConvertError和消息“”'不是有效的整数值,因此您的转换器告诉您您试图转换空字符串…您确定每个单元格中都有数字吗?对于二维数组,为了引用每个元素,我使用了两个嵌套循环。这为矩阵中的每列和每行提供了一个计数器变量。这不是要点:我告诉您,您的单元格数组包含空字符串,因此无法转换为数字数组,因为
strotint
不知道如何处理空字符串。如果您希望将无法解释为有效
int
的序列转换为d,请尝试使用
strotintdef
默认值,例如0。