我有这段代码从(1 2 3)文件中打印出矢量vector.txt,但是每当我运行代码将矢量转换为matrix时,填充0matrix就会显示为。请帮忙

#include<iostream>
#include<conio.h>
#include <stdio.h>

using namespace std;

void main()
{
    cout << "Loading vector.txt" << endl;
    FILE *file = fopen("vector.txt", "r");
    int vector[3];
    int b = 0;

    do{
        fscanf(file, "%i", &vector[b]);
        b++;
    }while(feof(file) == 0);


    //clear the screen.
    fclose(file);

    cout << "Loading matrix" << endl;

    int a[3][3],i,j;
    for(int i=0;i<3;i++)
    {
        for(b=0; b<3;b++);
        a[0][i] = vector[i];
    }

    cout << " Vector rotation" << endl;


//Display the original matrix
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
    {
        cout<<a[i][j]<<" ";
    }
        cout<<endl;
    }
        cout<<"Transpose of above matrix is: "<<endl;
//Display the transpose matrix
    for(j=0;j<3;j++)
    {
        for(i=0;i<3;i++)
        {
        cout<<a[i][j]<<" ";
        }
    cout<<endl;
    }
//get character
    getch();
}

最佳答案

使用={}初始化矩阵0:

int a[3][3] = {},i,j;

关于c++ - 0的数组显示为-85993460,而不是0,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25570923/

10-11 22:39