Quick question

I am trying to decipher the following code, it is intended to read a take a string argument which is the name of a file to read.
1
2
3
4
5
6
 public:
    Text() {}                       //constructor 1
    Text(const string& fname) {    //constructor
        ifstream ifs(fname.c_str());
        string line;
        while (getline(ifs, line))


My question is, what should I name the file to be read in the directory?
fname? ifs?

Thanks
who cares what name you give your variable?
You can name the variable whatever you want? If you feel ifs works then use it? It is recommended however to use variable names that have more meaning and understanding.
fname and ifs are just variable names used in your code. The fname variable holds the filename that is passed to the Text constructor. So you can use whatever filename you want as long as you pass it to the constructor when creating the Text object.

 
Text obj("whatever-your-file-is-called.xyz");
Last edited on
Topic archived. No new replies allowed.