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
| #include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include "AAA.h"
#include "BBB.h"
using namespace std;
vector <AAA> AAAList;
vector <BBB> BBBList;
void Lecture()
{
string mon_fichier = "data.txt";
ifstream dataBase(mon_fichier.c_str(), ios::in);
if(dataBase)
{
while (!dataBase.eof())
{
if (!dataBase.eof())
{
string command, dump, sub, trash;
int i=0; //initailize 2 string
dataBase >> command; //we read the first word, with >> we scroll in the file word by word
if (command=="#")
{
getline(dataBase,dump); //put the line in the variable dump
cout << dump << endl;
istringstream iss(dump); //to cut the in words
while (iss)
{
iss >> sub; //to enumerate the nomber of word
i=i+1;
}
}
else if (command=="aaa")
{
string AAAName;
double x, y, z;
dataBase >> AAAName;
dataBase >> x;
dataBase >> y;
dataBase >> z;
AAAList.push_back( AAA (AAAName,x,y,z) );
}
else if (command=="BBB")
{
string BBBName;
double X,Y,Z;
dataBase >> X;
dataBase >> Y;
dataBase >> Z;
BBB.push_back( BBB (BBBName,X,Y,Z) );
}
}
else
{
break; //stop the loop if we are at the end of the file
}
}
}
else
{
cout << "Impossible d'ouvrir le fichier !" << endl;
}
dataBase.close(); // close dataBase file
} |
Partager