I am working on a project that inputs stock information from files, then outputs the information when the customer is called upon. I am doing pretty good, but am stuck. This is what I have.
for (int k = 0; k < namevector.size(); k++){ //namevector is a vector of type
otherfile.close(); customer(defined as a class)
otherfile.clear();
otherfile.open(namevector[k].getname().c_str());
if (!otherfile.is_open()){
cout << "Can't open the customers stock file" << endl;
}
while(!otherfile.eof()){
otherfile >> symbol >> numshare >> price;
stocks.setsymbol(symbol);
stocks.setnumshare(numshare);
stocks.setprice(price);
stockvector.push_back(stocks); //stockvector is vector of type stock
which is defined as a class
}
}
cout << "Enter customer name, or exit" << endl;
cin >> command;
for (int n = 0; n < 3; n++){
if (command == namevector[n].getname()){
cout << "found person" << endl;
for(int m = 0; m < 3; m++){
cout << namevector[n].getstock(m).getnumshare()<<
namevector[n].getstock(m).getsymbol()<<
namevector[n].getstock(m).getprice() <<
namevector[n].getstock(m).getnumshare() * namevector[n].getstock(m).getprice() << endl;
}
The problem (I believe) is that when I read the data in from the files (there is a seperate file for each customer) it puts all of it into the same stockvector, so that when I try to call for a specific customer, it doesn't match up with the stock for that customer. Can I create more than one stockvector, or is that impractical?
Please let me know if you need any more code, like my class functions, but I don't believe they are the problem, although I could be wrong.