I am reading a file then printing the data onto the other file. It is working, however when I check to see if each variable is being properly set after reading the file a issue arrises.
Example of the file being read
Example of the outputCode:Vehicle PV50CAN passed camera 1 at 05:33:26.
Vehicle W867BRO passed camera 1 at 05:33:29.
Vehicle KQ63ARU passed camera 1 at 05:33:38.
Vehicle K954ITQ passed camera 1 at 05:33:40.
Vehicle V220MXB passed camera 1 at 05:33:42.
Vehicle Q762YIV passed camera 1 at 05:34:10.
Vehicle O858FGA passed camera 1 at 05:34:10.
Vehicle V445ECN passed camera 1 at 05:35:14.
Vehicle V646ADL passed camera 1 at 05:35:15.
[/code]Code:PV50CAN 1 05:33:26.
W867BRO 1 05:33:29.
KQ63ARU 1 05:33:38.
K954ITQ 1 05:33:40.
V220MXB 1 05:33:42.
Q762YIV 1 05:34:10.
O858FGA 1 05:34:10.
V445ECN 1 05:35:14.
V646ADL 1 05:35:15.
C840BAK 1 05:35:16.
In the console I am getting:
PV5
05:33:26.\
1
3ARU
K95
05:33:40.\
1
2YIV
O85
05:34:10.\
1
6ADL
C840
05:35:16.\
1
RKG
I read the file and send the information I need to the output file. I then read it doing the following
Code:std::ifstream readSortedFile;
std::string plates;
std::string camera;
std::string time;
readSortedFile.open("outFile.txt",std::ios::in);
while(readSortedFile>>plates>>camera>>time){
I then check the values that is being places in the variables.
I check each one and they are all getting the same values. I need each variable to to be set properly. Not all of them having identical information.Code://std::cout<<plates<<"\n";
std::cout<<camera<<"\n";
//std::cout<<time<<"\n";
vehicle.setLicensePlate(plates);
vehicle.setCamera(camera);
vehicle.setTime(time);
// std::cout<<vehicle.getCamera()<<"\n";
Whole Code
Code:#include <iostream>
#include "Calculate.h"
#include "Vehicle.h"
#include <fstream>
Calculate::Calculate(){
}
void Calculate::readFile(){
std::ifstream reader;
std::ofstream writer;
writer.open("outFile.txt");
reader.open("carSpeeds.txt",std::ios::in);
std::cout << "Reading from the file" << std::endl;
while (reader>>line) {
if (line=="Vehicle"||line=="Speed"||line=="limit"||line=="is"
||line=="passed"||line=="camera"||line=="at"||line==".\\") {
//erase the string if it matches
line=" "; //create a space so there is not a mega string
}
//write string to outfile
writer<<line<<std::endl;
}
reader.close();
writer.close();
//read file after it has been sorted and all unnessary strings have been removed
std::ifstream readSortedFile;
std::string plates;
std::string camera;
std::string time;
readSortedFile.open("outFile.txt",std::ios::in);
while(readSortedFile>>plates>>camera>>time){
//std::cout<<plates<<"\n";
std::cout<<camera<<"\n";
//std::cout<<time<<"\n";
vehicle.setLicensePlate(plates);
vehicle.setCamera(camera);
vehicle.setTime(time);
// std::cout<<vehicle.getCamera()<<"\n";
}
}
void Calculate::calculateSpeed(){
}