How to Pass String to a function in order to read a file

Joined
Feb 13, 2009
Messages
1
Reaction score
0
Hi I am trying to create a function that can read a file after i pass the filename but I having trouble doing so. Can anyone please tell me where I am going wrong with this thanks. My code is below

AvgimpliedVolatility is my function's name.

double AvgImpliedVolatility (const string& filename, char optiontype, double Time, double Interest_rate, double OptionSpotPrice)
{
ifstream myfile(filename);
if(myfile.is_open())
{
while (!myfile.eof() )
{
//read data file
getline (myfile,line);
cout << line << endl;
............

when i replace filename with the exact name of the file for example:"sp500.csv" the code works fine.

Please advise. I will be reading different file which is the reason I am trying to create that function.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top