I'm working on a program that reads in from a file a list of customers and puts them in a vector. I did that. Next, there is a file for each customer that I put in this vector. I need to open the file, and "assign the data to a new instance of the class in the vector." I don't really know what this means. I have a class of stocks, where a stock consists of three arguements, a symbol, amount of stock and price. My class looks like this:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class stock {
private:
string symbol;
int numshare;
float price;
public:
stock(string symbol1, int numshare1, float price1);
stock();
};
There are other things in the class but I believe this is all that is important for my problem.
The files I am reading in look something like this:
CSCO 100 12.34
MSFT 200 56.78
where the numbers are the symbol, followed by numshare, follewed by price.
This is what I have been trying, and it hasn't been working:
for(int j = 0; j<namevector.size(); j++){
otherfiles.open(namevector[j].c_str());
while(!otherfiles.eof()){
otherfiles >> symbol >> numshare >> price;
if (!otherfiles.eof()){
stockvector.push_back(symbol, numshare, price);
}
}
otherfiles.close();
otherfiles.clear();
}
where namevector is my vector of customernames, they are the names of the files I have to open.
I'm really sorry, I know this probably isn't very clear, but it's the best job of explaining i can do.