constructors containing files

Im confused on creating a constructor.

I need to make a constructor that takes in 1 string argument, a string file name

the file has about 30 prices of something for a certain date and it goes into a data member prices

1
2
3
4
  Market::Market(string file_name)
{
	
}


I pretty much have nothing because I am confused on adding the file. its a txt file and would I put in the header #inlude"file name" and how would I make it go into the data member
If this Market object is meant to know about the information inside the file, named file_name, then in the constructor the Market object should open that file and read the information from the file.

http://www.cplusplus.com/doc/tutorial/files/
these are the directions
map<long, vector<double> > prices. The prices of the 30 stocks on the date (the key). The
prices are in order of the elements in symbol_list (that is, alphabetically by short name)

write a constructor that takes a single string argument, a string file name
-That file contains closing stock prices for 30 stocks of the Dow Jones for a particular date (see
format below). It populates the data member

im still confused how to go about this
would i still use the fstream stuff that you posted ?


The file contains 30 data values. Date, price.

You are to write a constructor that reads the file, and puts the data into an object of type map<long, vector<double>> .

You would use the fstream stuff I posted
Last edited on
Topic archived. No new replies allowed.