Hello,
So I am trying to read a text file into an array, but I am having issues breaking it up properly.
Here is my text file:
0 Car Fixed
1 Brake
2 Windshield
3 Tires
4 Engine
5 Doors
6 Transmission
and here is my code:
#include <iostream>
#include <string>
#include <fstream>
#include "CarLot.h"
#include "Main.h"
using namespace std;
struct RepairList {
int repairCode[12];
string repairPart[12];
};
void RepairsFile() {
RepairList rList;
string list;
ifstream repairs;
repairs.open("RepairsKey.txt");
while (getline(repairs, list)) {
for (int i = 0; i < 12; i++) {
if (list.at(0) == '0') {
rList.repairCode[i] = i;
repairs >> rList.repairPart[i];
}
else if (list.at(1) == '1') {
rList.repairCode[i] = i;
repairs >> rList.repairPart[i];
}
else if (list.at(2) == '2') {
rList.repairCode[i] = i;
repairs >> rList.repairPart[i];
}
else if (list.at(3) == '3') {
rList.repairCode[i] = i;
repairs >> rList.repairPart[i];
}
else if (list.at(4) == '4') {
rList.repairCode[i] = i;
repairs >> rList.repairPart[i];
}
else if (list.at(5) == '5') {
rList.repairCode[i] = i;
repairs >> rList.repairPart[i];
}
else if (list.at(6) == '6') {
rList.repairCode[i] = 6;
repairs >> rList.repairPart[i];
}
else if (list.at(7) == '7') {
rList.repairCode[i] = i;
repairs >> rList.repairPart[i];
}
}
}
repairs.close();
}
int main() {
RepairsFile();
system("pause");
return 0;
}
What I need it to do is to read each number and output the part needing to be fixed, but what I keep getting is that it's reading each number and letter and storing each one into the array instead of skipping over the number and getting the part.
So if I go to input 1 it would output Brake, but 3 would output Windshield instead of Tires......
https://www.daniweb.com/community/contribute/3#
What am I missing?! Any input would be helpful.
Thank you!