我对C ++还是很陌生,所以请原谅我的无能。这是代码,它是关于尝试找到2个矩阵的和:
#include <iostream>
#include "functions.h"
using namespace std;
void saisir_matrice(int l, int c, int matriceA[][colonnes], int matriceB[][colonnes])
{
cout << "Entrez vos numéros" << endl;
for (int i = 0; i < l; i++)
{
for (int j = 0; j < c; j++)
{
cin >> matriceA[i][j];
}
}
}
我不确定是什么问题,但是第一行出现了一些错误,例如:
期望int前的合格ID
符号科隆无法解析
在','标记之前期望')'
我知道这些错误的含义,这意味着我编写函数的方式存在问题,但我似乎在第一行中找不到它们。
编辑,这是到目前为止的功能。h:
#ifndef FUNCTIONS_H_
#define FUNCTIONS_H_
void saisir_matrice(int lignes, int colonnes, int matriceA[][colonnes], int matriceB[][colonnes]);
#endif /* FUNCTIONS_H_ */
这是我的主要功能:
#include <iostream>
#include "functions.h"
using namespace std;
int main()
{
int COLONNES;
int LIGNES;
cout << "entrez 2 nombres" << endl;
cin >> COLONNES;
cin >> LIGNES;
int matriceA[LIGNES][COLONNES];
int matriceB[LIGNES][COLONNES];
saisir_matrice(LIGNES, COLONNES, matriceA, matriceB);
return 0;
}
重点是尝试将数组作为变量传递,但是我找不到很多语法错误。这是错误消息:
- Symbol 'colonnes' could not be
resolved
- Symbol 'colonnes' could not be
resolved
- expected ‘)’ before ‘,’ token
- expected unqualified-id before ‘int’
答案 0 :(得分:0)
做到这一点的一种方法是
#include <iostream>
using namespace std;
void saisir_matrice(int l, int c, int *pmatriceA, int *pmatriceB)
{
cout << "Entrez vos numéros" << endl;
for (int i = 0; i < l; i++)
{
for (int j = 0; j < c; j++)
{
cin >> *(pmatriceA + (i * c) + j);
}
}
for (int i = 0; i < l; i++)
{
for (int j = 0; j < c; j++)
{
cout << *(pmatriceA + (i * c) + j) << endl;
}
}
}
int main()
{
int COLONNES;
int LIGNES;
cout << "entrez 2 nombres" << endl;
cin >> COLONNES;
cin >> LIGNES;
int matriceA[LIGNES][COLONNES];
int matriceB[LIGNES][COLONNES];
saisir_matrice(LIGNES, COLONNES, &matriceA[0][0], &matriceB[0][0]);
return 0;
}