A traves de un fichero se pide imprimir por pantalla sus datos usando STL o contendores, he hecho este codigo pero da varios errores
MAIN
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include "Sensor.h"
using namespace std;
int main()
{
vector <Sensor> VecDatos;
if(leeFichero(VecDatos))
{
cout << "Referencia" << "\t Lectura" << "\t Fecha y Hora" << endl << endl;
for(size_t i=0; i<VecDatos.size();i++)
{
cout << VecDatos[i];
}
}
}
CLASE
#ifndef SENSOR_H
#define SENSOR_H
#include <vector>
#include <iostream>
enum CodigosError {SUCCESS, ERROR_OPENING_FILE, ERROR_DENOMINATOR_IS_ZERO};
class Sensor
{
double lectura;
std::string referencia;
time_t tiempo;
public:
friend void leeFichero(std::vector<Sensor> &v);
std::istream& operator>> (std::istream &in, Sensor &s):
std::ostream& operator<< (std::ostream &out, Sensor &s);
};
#endif // SENSOR_H
FUNCIONES
#include "Sensor.h"
#include <fstream>>
void leeFichero(std::vector<Sensor> &v)
{
Sensor s;
std::ifstream FichSensores("datos.txt");
if(!FichSensores)
throw ERROR_OPENING_FILE;
while(FichSensores)
{
FichSensores>>s.lectura;
FichSensores>>s.referencia;
FichSensores>>s.tiempo;
if(!FichSensores.fail())
{
v.push_back(s);
}
}
FichSensores.close();
}
std::istream& operator>> (std::istream &in, Sensor &s)
{
in>> s.lectura;
in>>s.referencia;
in>>s.tiempo;
while(!lectura)
{
std::cout<<"La entrada no puede ser 0"<<std::endl;
}
return in;
}
std::ostream& operator<< (std::ostream &out, Sensor &s)
{
if(!s.lectura!=0)
{
out<<s.referencia<<"\t" <<s.lectura<<"\t"<<s.tiempo<<"\t";
}
return out;
}