1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include <vector> //pour std::vector
#include <string> // pour std::string et std::getline
#include <sstream> //pour std::istreamstring
#include <iostream> //pour les std::cout, std::cin....
#include <fstream> //pour lire les fichiers
std::vector<std::vector<int> > MatriceA;
std::ifstream fichier("toto.txt");
if(fichier)
{
std::string tmpLine;
while(std::getline(fichier,tmpLine))
{
std::vector<int> tmpVector;
std::istringstream toto(tmpLine);
std::string mot;
while ( std::getline(toto, mot, ';' ) )
{
std::istringstream mot_nombre(mot);
int nombre;
mot_nombre >> nombre;
tmpVector.push_back(nombre);
}
correlation.push_back(tmpVector);
}
////-- Display Matrice:
//std::vector<std::vector<int> >::iterator ita = MatriceA.begin();
//std::vector<int>::iterator ita2;
//while(ita != MatriceA.end())
//{
// ita2 = ita->begin();
// while(ita2 != ita->end())
// {
// std::cout<<"\t" <<*ita2;
// ita2++;
// }
// std::cout<<std::endl;
// ita++;
//}
////-- Or display again with []
//-- get indice I and indice j
std::vector<std::vector<int> >::iterator ita = MatriceA.begin();
std::vector<int>::iterator ita2;
long xlen =0;
long ylen =0;
if(ita !=MatriceA.end())
{
ylen=MatriceA.size(); //Y axis
xlen =MatriceA[0].size(); //X axis
}
for(long i =0; i<ylen; i++)
{
for(long j=0; j<xlen; j++)
{
std::cout<<"\t" <<MatriceA[j];
}
std::cout <<std::endl;
}
}
std::cin.ignore();
return 0; |
Partager