Hi,
I have wrote a program which places the contents of three array's into a txt file.
The 3 arrays (total of 10 different items):-
char string (food's name)
double (food's price)
bool (is food's price over £5)
Now instead of using the 3 arrays, I want to read contents from this txt file and place the contents into an array of structs.
Being new to this, I'm just starting with trying to read the txt file, but the lines in bold below are causing me problems, and am looking for some help.
Been struggling with all this all day, so any help will be a big help.Code:#include <iostream> #include <fstream> using namespace std; const int MAXCHARS = 20; const int MAXITEMS = 10; struct mystruct { char itemname[MAXITEMS][MAXCHARS]; double price; bool luxury; }; int main() { mystruct mystructname; ifstream mystream("myfile2.txt"); if(!mystream) { cout << "phail " << endl; } mystream >> mystruct.price; cout << mystructname.price; mystream.close(); system ("pause"); return 0;
Many thanks!



LinkBack URL
About LinkBacks



