So we have a text file with the following data:
Year - Make - Model - Price
2011 Chevrolet Tahoe $30588
There is only 1 space between everything. There is a Dollar Sign ($) in front of the price. We still have to have miles in our code, even if it's not in the data file. I don't know why.
How would I go about getting this information from a text file?
I have tried a bunch of methods, and none of them seem to work.
Here is the code that grabs the information:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <ctime>
#include "car.h"
using namespace std;
const int number=3;
const int maxPrice=25000;
int main()
{
int a;
string b; string c;
float d;
float e;
car cars [number];
int i, j;
float temp; //Price
int temp2; //Year
string temp3; //Make
string temp4; //Model
float temp5; //Miles
ifstream inFile; //declaring the File
inFile.open("carData.txt");
for(i=0; i<number; i++)
{
//cout << "Enter the YEAR of the car: ";
inFile >> a;
cars[i].setYear(a);
//cout << "Enter the MAKE of the car: ";
getline(inFile,b);
cars[i].setMake(b);
//cout << "Enter the MODEL of the car: ";
getline(inFile,c);
cars[i].setModel(c);
//cout << "Enter the number of MILES on the car: ";
inFile >> d;
cars[i].setMiles(d);
//cout << "Enter the PRICE of the car: ";
inFile >> e;
cars[i].setPrice(e);
//cout << " " << endl;
}
// ...
}
The main continues much further than that, this is just to getline all of the data. I've really been having trouble with this all day. I've seen so many different methods.