File Not open

I have developed a code here that opens the input file. If the file does not open, I want it to prompt "file not open." The problem in code is that I have created an input file that has data on it and I even have it open during the runtime. I'm still getting an output on the console saying "The file is not open," especially when it is.

1
2
3
4
5
6
7
8
9
10
11
12
13
 //make a file for input
void make_input(ifstream &fin,string &filename)

{
	cout<<"Input File: ";
	getline(cin,filename);

	//Open the file
	fin.open(filename);
		//if file doesnt open
			if(!fin)
				cout<<"\nFile not open";
}
From this website:
http://www.cplusplus.com/reference/fstream/ifstream/open/

std::ifstream::open
cplusplus wrote:
...If the stream is already associated with a file (i.e., it is already open), calling this function fails.

Seeing as you are passing the ifstream object by reference, make sure it is not already opening a file prior to trying to use it to open another file
Last edited on
Kind of confused on this, but how necessarily do I fix this? just to make, is this code written correctly though?
Topic archived. No new replies allowed.