Hi again,
Finally got my linker error solved and now am having trouble when reading data in from a file. The data file reads in an integer, a string, and then two more integers. It compiles okay, but when running the output all that is displayed is the first integer, first word in the text and then memory addresses from there on out. I assume this has something to do with how the string is being read in from the file. My professor also mentioned that since there are spaces and commas used in the .txt file that we will need to use a delimiter. Can anyone help? Here is the code that is giving me trouble:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
int loadVehicles(int numItems, int carType[], string carName[], float costMaterials[], float numHours[])
{
numItems = 0;
int count;
ifstream inputFile;
inputFile.open("cars.txt");
for (count = 0; count < 100; count ++)
{
inputFile >> carType[count] >> carName[count] >> costMaterials[count] >> numHours[count];
}
inputFile.close();
// Test
cout << "The vehicles are: ";
for (count = 0; count < 100; count ++)
{
cout << carType[count] <<" "<< carName[count] <<" "<< costMaterials[count] <<" "<< numHours[count];
cout << endl << endl;
}
count = numItems;
cout << numItems << endl << endl;
return numItems;
}
|
Any help is greatly appreciated. I have already had success in such a short time here on the forum, and am extremely grateful for it. Thanks for helping me out guys!
Cheers,
Zach
P.S. Here is the text that the function is supposed to read in:
1 Aston Martin One-77, 189000 10
1 Lamborghini Murcielago, 22000 10
2 Ferrari F430 Spyder, 14500 10
2 Lamborghini Gallardo Spyder, 18600 10
3 Aston Martin Rapide, 18400 10