Very noobish, simple question, which hopefully has an easy answer. My issue basically comes down to a single line of code on a function parameter that is:
void className::read(const string &)
{
ifstream fin;
fin.open(fname);
/* ...function code */
fin.close()
}
The input is established in main as a string, fname (i.e. object.read(fname)).
When I do this, it tells me that fname has not been declared in this scope. My question, thus, is how to use fname, the input, as the file name in fin.open().
Thanks to everyone who has already helped and sorry for the poor explanation of the issue earlier.
If fname refers to the function parameter well you can because it has a const modifier. So you’d have to remove the const modifier. Once that is done it’s like assigning to any other variable.
If however you meant use the value of fname within the function well that’s even simpler, you just create a new variable and assign it: