let say that i have a file
ID Name Month Actual Quantity Desired Quantity Cost
2 pepsi 1 1 3.3
3 pepsi 2 3 5.3
how would i read that into a vector called vector<Item> items; where Item is a class that consists of those names as listed in the list. i have a set() methods for all of them but how would i read one of each values and set it for example setID() and its value and if it is empty put a value -1. What i have so far is just a basic file open
char file_name[81];
cout<<"Enter a file to open (ex: file.txt): ";
cin.ignore();
flush(stdin);
cin.getline(file_name, 81);
ifstream input(file_name);
should i use a istringstream or what?
UPDATE:
char file_name[81];
cout<<"Enter a file to open (ex: file.txt): ";
cin.ignore();
cin.getline(file_name, 81);
ifstream input(file_name);
string line;
getline(input,line);
while (getline(input,line)){
BUT I get an error: statement cannot resolve address of overloaded function at line : ifstream input(file_name)
They way I would do is is to start writing a suitable input operator:
Once this operator is in place, you can read the file using something like this: