Hi ,
I have a question about passing arguments in a constructor. I need to be able to pass a string in a constructor. THis string in turn will be used to open a file by that same name. I am storing this name as a private member of a class
I can pass the string, but when I get to opening a file by that name, I am not sure how to do this. I do have this in different files, but put in one file here.
I have posted the code below, along with where I am not sure how to open a file with the same name as the string that was passed in the constructor.
Any help will be appreciated. THanks for any help.
Code:#include <iostream> #include <fstream> #include <string> class data { public: data(string); //contructor void somefunction(); private: string name; }; data::data(string somename) {name = somename;} void data::somefunction() { ofstream outfile; outfile.open(name); //??? question about passing the stored string name here? /*----- some output code----*/ outfile.close(); } int main () { data one("somename"); one.somefunction(); }