Struct Involving Reading From File
Text File:
Car,1996.75
Truck,3971.54
Motorcycle,1429.09
Freight Train,356478.98
*****START CODE********
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int NUM_OF_ITEM = 8;
struct vehItemType
{
string vehItem;
double vehPrice;
};
void getData(vehItemType vehList[NUM_OF_ITEM], ifstream& menuData);
int main()
{
ifstream vehData;
vehItemType vehList[NUM_OF_ITEM];
int counter;
vehData.open("C:\\veh.txt");
if(!vehData)
{
cout << "Error: file could not be opened." << endl;
return 1;
}
getData(vehList, vehData);
cout << "Welcome To Johnny's Dealership" << endl;
cout << "Vehicle Items:" << endl << endl;
cout << fixed << showpoint << setprecision(2);
for(counter = 0; counter < 8; counter++)
{
cout << setfill(' ') << left << setw(20) << vehList[counter].vehItem << ":" << right << "$" << vehList[counter].vehPrice << endl;
}
cout << endl;
} //end main
void getData(vehItemType vehList[NUM_OF_ITEM], ifstream& menuData)
{
int line = 0;
while(!vehData.EOF())
{
getline(vehData,menuList[line].menuItem,',');
getline(vehData,menuList[line].menuPrice,);
counter++;
}
vehData.close();
} // end getData
******** END CODE ************
I get errors regarding "cannot convert int to string" or something along those lines. I understand that the error will no longer present if I change the struct to:
struct menuItemType
{
string menuItem;
string menuPrice;
};
I am looking to know how to read the text from the file correctly to allow the text string to be read as well as the number. In addition have the item displayed as in the code. I need to retain the double so I can perform calculations down the line.
I've been beating my head against the desk for a week giving it the best try I can. Any help would be appreciated. Thank you!

