Witam, mam pytanie jak wyświetlać vector dwuwymiarowy? Mam coś takiego, ale nie działa
vector<vector<cMatrix>> vec;
void cMatrix::wyswietl()
{
for( auto v=vec.begin(); v!=vec.end(); ++v)
{
for (auto w=v->begin(); w!=v->end(); ++w)
cout<<w;
}
}
Witam, mam pytanie jak wyświetlać vector dwuwymiarowy? Mam coś takiego, ale nie działa
vector<vector<cMatrix>> vec;
void cMatrix::wyswietl()
{
for( auto v=vec.begin(); v!=vec.end(); ++v)
{
for (auto w=v->begin(); w!=v->end(); ++w)
cout<<w;
}
}
#include <vector>
#include <iostream>
using namespace std;
int main() {
vector<vector<int>> table = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
for(auto const &row: table) {
for(auto el: row) {
cout << el << " ";
}
cout << endl;
}
}
Dziękuje
A da się to zrobić w sposób podobny do przedstawionego przeze mnie? ;)
tak.
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)
class cMatrix
{
int kolumny;
int wiersze;
public:
vector<vector<int>> vec;
void wyswietl();
void rozmiar();
void uzupelnij();
cMatrix();
cMatrix(int a, int b);
cMatrix (const cMatrix & M);
};
void cMatrix::wyswietl()
{
for( auto v=vec.begin(); v!=vec.end(); ++v)
{
for (auto w=v->begin(); w!=v->end(); ++w)
cout<<*v;
cout<<endl;
}
}
void cMatrix::uzupelnij()
{
int tmp;
for(int i = 0; i<kolumny; i++)
{
for (int j = 0 ; j<wiersze; j++)
{
cin>>tmp;
vec.push_back( vector <int>( tmp ) );
}
}
}
void cMatrix::rozmiar()
{
cout<<"Podaj ilosc kolumn: ";
cin>>kolumny;
cout<<"Podaj ilosc wierszy: ";
cin>>wiersze;
}
cMatrix::cMatrix (const cMatrix & M)