My definition of "Whole Code" would be a program that can be compiled and ran,
I did that because I assumed no one would want to compile the code, I just showed the important code that pertains to the question. I thought I would annoy you guys by posting an entire program rather then narrowing down the issue and seeking advice. However I will post the "WHOLE CODE" below:
Code:
#include <iostream>
#include "Calculate.h"
int main(int argc, const char * argv[]) {
Calculate cal;
cal.readFile();
return 0;
}
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 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(){
}
Code:
#ifndef __Vehicle_Speed__Calculate__
#define __Vehicle_Speed__Calculate__
#include <stdio.h>
#include <string>
#include <vector>
#include "Vehicle.h"
class Calculate {
private:
std::string line;
std::vector<std::string> readerVector;
Vehicle vehicle;
public:
Calculate();
void readFile();
void calculateSpeed();
};
#endif
Code:
#include <iostream>
#include "Vehicle.h"
Vehicle::Vehicle(){
}
bool Vehicle::isSpeeding(){
return true;
}
void Vehicle::setLicensePlate(std::string plates){
this->plates=plates;
}
std::string Vehicle::getLicensePlate(){
return plates;
}
void Vehicle::setCamera(std::string camera){
this->camera = camera;
}
std::string Vehicle::getCamera(){
return camera;
}
void Vehicle::setSpeed(std::string speed){
}
double Vehicle::getSpeed(){
return speed;
}
void Vehicle::setTime(std::string vtime){
this->vtime=vtime;
}
std::string Vehicle::getTime(){
return vtime;
}
Code:
#ifndef __Vehicle_Speed__Vehicle__
#define __Vehicle_Speed__Vehicle__
#include <stdio.h>
#include <string>
class Vehicle {
private:
double speed;
std::string camera;
std::string plates;
std::string vtime;
std::string licensePlate;
public:
Vehicle();
bool isSpeeding();
void setLicensePlate(std::string);
std::string getLicensePlate();
void setCamera(std::string);
std::string getCamera();
void setSpeed(std::string);
double getSpeed();
void setTime(std::string);
std::string getTime();
};
#endif
Why are you writing this information to a file instead of just filling in your class variables when you read the input file, instead of writing the file to an output file then opening and reading that file? File reading and writing is orders of magnitude slower than in memory operations.
The format of the file I am reading is:
Code:
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.
I wanted to filter the information and have a way to check what was going wrong. So I made an output file checking if it was filtering correctly then just decided to read from that file too to see if I was still having the issue.
Which worked and the output file had:
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
ocdrew21, do yourself a favor and use
That could create its own problems...