Error while checking if .txt file is open or not

I want to check if a file is open or not. If not then open it.
1
2
3
ifstream inputFile;
if (!inputFile.is_open())
{ inputFile.open("filename.txt"); }


When I try to run the code in Visual Studio 2013, I get an error that the "!" is illegal.
error C2276: '!' : illegal operation on bound member function expression 

But when I try to run the same exact code in Netbeans 8.0.2, it works perfectly.

Can someone help me with this?
Last edited on
Topic archived. No new replies allowed.