I am trying to store a text file that contains 3 columns ( unsigned int/ string /float) of 57 rows into a vector that holds a struct of 'items'. With my code written I am able to store and print out the first line given in the text file.
I have been messing around w/ the push_back function of vector but seem to be implementing it incorrectly. Desired output is to have a vector that is 57 elements in length each holding a struct 'item' containing the 3 different variables of unsigned int / string / float. Any help is appreciated.
You created items as vector of chars, but in line 72 you try to push to it entry, which is not a char. What you should do is to make a loop that will go as many times as needed, in your case: 57, and inside create an item for each line of text:
1 2 3 4 5 6 7 8 9
vector<item> items;
for(int i = 0; i < dataFromFile.length(); i++) {
item entry;
entry.barcode = /*Extract Barcode from dataFromFile[i]*/;
entry.item_name = /*Extract Name from dataFromFile[i]*/ ;
entry.price =/*Extract Price from dataFromFile[i]*/;
items.push_back(entry);
cout << items[i].barcode << items[i].item_name.c_str() << items[i].price << endl;
}