ok, here's my problem. i can write to a file just great. it formats it exactaly how i want it to. the problem is that i can't read from a file. everytime i try to read from a file and i want something other than a char array, it doesn't read correctly, and with my current reading system it won't read correctly for even that. can i get a few pointers?
i'm confident that this is where my problem is.
Code:
char inName[100]; // name of the food
int inCategory; // what kind of food
float inCalories; // calories
float inCarbohydrates; // grams
float inFat; // grams
float inCholesterol; // grams
float inSodium; // grams
float inProtein; // grams
ifstream in("data.txt");
counter = 0;
while(in.peek() != EOF)
{
in.getline(inName, 100, '~');
inCategory = (int)in.get();
inCalories = (float)in.get();
inCarbohydrates = (float)in.get();
inFat = (float)in.get();
inCholesterol = (float)in.get();
inSodium = (float)in.get();
inProtein = (float)in.get();
data[counter].setname(inName);
data[counter].setcategory(Category(inCategory));
data[counter].setcalories(inCalories);
data[counter].setcarbohydrates(inCarbohydrates);
data[counter].setfat(inFat);
data[counter].setcholesterol(inCholesterol);
data[counter].setsodium(inSodium);
data[counter].setprotein(inProtein);
counter++;
}
in.close();
but i don't know what i need to change.
this is what is in data.txt
Multi grain bread~6 90 16 0 .5 .125 4
the goal is to get it to read until the tild, and made that the name, then read the next number, make that the food group, red next number, make that the calories, etc etc.
thanks for taking the time to view my thread