I have created a text file that contains strings and numbers. so I want to make a program that reads these data, but I am stuck in extracting these data and store them into an array of structs..I don't know why it doesn't work... Could anyone help?
Thanks a lot
here is my program:
#include <iostream>
#include <fstream>
using namespace std;
int SIZE = 10;
struct MenuItem
{
    string name;
    float price;
};
float ReadItem( ifstream &in, MenuItem &d )
{
    getline( in, d.name );
    in >> d.price;
    in.ignore();
    return 0;
}
void PrintItem( ostream &out, MenuItem d )
{
    out << "Item name: " << d.name
        << " Price: " << d.price << endl;
    return;
}
int main()
{
    ifstream fin( "text.txt" );
    int i = 0, j;
    MenuItem data[SIZE];
    while( !fin.eof() )
    {
        ReadItem( fin, data[i] );
        i++;
    }
    fin.close();
    for( j = 0; j < i; j++ )
    {
        PrintItem( cout, data[j] );
    }
    return 0;
}
