百萬感謝任何人,誰願意幫助我。類型錯誤引用的初始化無效
首先,代碼:
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
void Beolvas (vector<vector<int> > mat);
bool VanNemNull (const vector<vector<int> > &mat);
int main()
{
cout << "Van-e a mátrixnak olyan oszlopa, hogy a főátló alatt csak 0-át tartalmaz, és ha igen, akkor melyik az?\n" <<endl;
char ch;
do{
// Adatbevitel
vector<vector<int> > mat;
Beolvas(mat);
//Kiértékelés
int i;
if (VanNemNull(&mat[i])) cout<<"szupiiiiii";
cout<< endl << "Futtassam újra? (I/N)";cin>>ch;
}while (ch!='n' && ch!='N');
return 0;
}
void Beolvas(vector<vector<int> > mat)
{
ifstream fajl;
bool hiba;
string str;
do{
cout << "Fajl neve:";
cin >> str;
fajl.open(str.c_str());
if (hiba = fajl.fail())
{
cout << "Nincs ilyen nevű fájl" << endl;
fajl.clear();
}
}while (hiba);
int n;
fajl >> n;
if (n<1)
{
cout<<"Helytelen a mátrix mérete\n Kérem ellenőrizze a forrásfájlt!\n";
cout<<"E megnyomásával kilép"<<endl;
char ex;
do{
cin>>ex;
}while (ex!='e' && ex!='E');exit(0);
}
mat.resize(n);
for(int i=0; i<n; ++i)
{
mat[i].resize(n);
for (int j=0; j<n; ++j)
{
fajl >> mat[i][j];
}
}
fajl.close();
cout<<"A mátrix a következöképpen néz ki:"<<"\n";
cout<<"Elemszáma: "; cout<<n*n<<"\n";
for (int i=0; i<n; ++i)
{
for (int j=0; j<n; ++j)
{
cout<<mat[i][j]<<"\t";
}
cout<<"\n";
}
}
/*void Vansor (const vector<vector<int> > mat)
{
//bool l = false;
}*/
bool VanNemNull (const vector<vector<int> > mat)
{
bool l = false;
int i=0;
cout<<(int)mat.size();
for (int j=i+1; !l && j<(int)mat.size(); ++j)
{
cout<<mat[j][i]<<"\n";
if (l) cout<<"hej\n";
l = (mat[j][i]!=0);
if (l= true) cout<<"22"; else cout<<"11";
}
return (l);
}
的主要問題(我認爲)是最後一部分。另外,我得到這些錯誤消息:
||In function `int main()':|
|23|error: invalid initialization of reference of type 'const std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&' from expression of type 'std::vector<int, std::allocator<int> >*'|
|9|error: in passing argument 1 of `bool VanNemNull(const std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&)'|
||=== Build finished: 2 errors, 0 warnings ===|
除了錯誤信息,你會遇到什麼樣的問題,即這是什麼應該做的和它有什麼作用呢?另外,請爲該問題選擇一個真正的標題。 – deceze 2011-05-17 01:58:04
對不起,但我現在不是最重要的東西。現在還沒睡好30個小時。 – Richard 2011-05-17 02:12:52
那麼也許是時候了。 :o) – deceze 2011-05-17 02:14:35