I have a file (Existingfile.txt)that contains details of food items as shown:
- Pasta 1.99
- Cheese cake 4.99
and so on. I have to write a c++ program that reads these records. Can I create a structure as follows to read the records like individual structures?
struct food
{
int no;
string name;
float cost;
}s;
//TO read from file
void read(){
fstream f;
f.open("Existingfile.txt",ios::in);
while(!f.eof()){
f.read((char*)&s,sizeof(s));
.
.
.
}
.
.
.
f.close();
}
P.S: I am new to stackoverflow. If my question is not correct, please comment and I will clear it. Please guys, I need your help!