Created
March 23, 2015 13:58
-
-
Save ABeltramo/1d914221d6c9932d46ba to your computer and use it in GitHub Desktop.
C++ vector[ vector [ ] ]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// | |
// Created by Ale on 23/03/15. | |
// Copyright (c) 2015 ABeltramo. All rights reserved. | |
// | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int main(int argc, const char * argv[]) { | |
int colonne = 3; //Numero di vettori che vuoi salvare | |
vector<vector<int>> Matrice; | |
//Inizializzo la matrice | |
//NECESSARIO! | |
for(int i=0;i<colonne;++i){ | |
vector<int> Vettore; //Questo è il vettore su cui devi salvare i tuoi dati | |
Vettore.push_back(i); //IO inserisco un valore a caso | |
Matrice.push_back(Vettore); //inserisci il vettore nella matrice | |
} | |
for(int i=0;i<Matrice.size();i++){ | |
//Ora puoi accedere al vettore facendo Matrice[i] | |
for(int j=0;j<Matrice[i].size();++i){ | |
//Qui dentro invece sto accedendo ai dati dell'iesimo vettore | |
cout << Matrice[i][j] << endl; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment