Aug 6, 2012 at 5:06am UTC
For some reason I can input all data form infile, except enum datatype , Anyone has any idea why? and how to correct it?
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 31 32 33
void sortRating()
{
int index, counter, iteration; // counter = total number of stocks in database; iteration is sort done
counter = checkDatabase();
stock list[counter+2]; //Make a array according to database size; extra 1 for gap, 1 for temp
ifstream infile;
infile.open("database.txt" , ios::in);
while (!infile.eof())
{
infile.ignore(1000,'\n' );
for (index = 0; index < counter; index ++)
{
infile >> list[index].ticker >> list[index].price >> list[index].ma50 >> list[index].ma200 >> list[index].EPS ;
infile >> list[index].perChangeMA50 >> list[index].perChangeMA200;
infile >> list[index].rating; // WHERE THE PROGRAM DOES NOT WORK.
//WITH COMMENTS 322 C:\Users\Gary Lee\Desktop\cpp //Project\working_on_sor rating.cpp
//no match for 'operator>>' in 'infile >> list[index].stock::rating'
//my infile input is a string "Strong_buy" not 0, 1, 2, 3
} }
for (iteration = 1; iteration < counter; iteration++)
{
for (index = 0; index < counter - iteration; index++)
if (list[index].rating > list[index+1].rating)
{
list[counter+2] = list[index];
list[index] = list[index+1];
list[index+1] = list[counter+2];
}
}
}
Last edited on Aug 6, 2012 at 5:47am UTC
Aug 6, 2012 at 5:09am UTC
Because an enum is its own type; it's the same reason you can't just serialize an arbitrary class you made without writing any operators for it.
Aug 6, 2012 at 5:16am UTC
1 2
infile >> ratingTemp;
ist[index].rating = static_cast <stock_rating>(ratingTemp);
does this help?
Last edited on Aug 6, 2012 at 5:16am UTC
Aug 6, 2012 at 5:28am UTC
no its does not.. coz my enum cannot be input as int then static cast ,, what should i do?
Aug 6, 2012 at 9:07am UTC
In what format is the enum stored in the file?
Aug 8, 2012 at 5:44am UTC
Thanks Peter, you are right,, I stored it as a string in the file,, I have changed storing it into 0 1 2 3 4 5 ,, but in that way, have to run to the program to see the rating.