Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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
C++ 向量读取错误矩阵<;向量<;int>&燃气轮机;关于C++;_C++_Matrix_Vector - Fatal编程技术网

C++ 向量读取错误矩阵<;向量<;int>&燃气轮机;关于C++;

C++ 向量读取错误矩阵<;向量<;int>&燃气轮机;关于C++;,c++,matrix,vector,C++,Matrix,Vector,您好,我假设输入读取矩阵的大小为n x n,对于每n个读取矩阵,我使用向量来定义矩阵,我的输入是: 6 100100 001010 000000 110000 111000 010100 我的代码是: #include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; vector<vector<int>> grid;

您好,我假设输入读取矩阵的大小为n x n,对于每n个读取矩阵,我使用
向量
来定义矩阵,我的输入是:

6
100100
001010 
000000 
110000 
111000 
010100
我的代码是:

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  vector<vector<int>> grid;

  while(cin >> n){

    grid.resize(n);
    for(int i=0;i<n;i++){
      grid[i].resize(n);
      for(int j=0;j<n;j++){
        cin>>grid[i][j];
      }
    }

    for (int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        cout<<grid[i][j];
      }
      cout<<endl;
    }
  }
  return 0;
}
对于我的感知,一条线不能有超过6个数字,需要有6个数字,所以我不知道它在做什么!
有人可以告诉我我做错了什么并解释原因。

当您输入数字
100100
时,它被视为一个整数,而不是6个整数。您应该在每个数字
1
0
之后按
Enter
键。除了打印错误外,您必须记住
100100
本身是一个整数,
std::cin::operator>
将立即读取它。要使其一次只读取一个
0
/
1
,请在中间插入空格,或从输入读取中间
bool变量
,然后从中间变量进行复制。
此外,如果您刚刚使用了
std::vector
s或
std::vector
(以防您将其视为文本),则不需要使用该选项。

coutok I编辑了您的更正,但输出无论如何都不正确。
1001001010011000011100010100
000000
000000
000000
000000
000000