954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Unable to Open File with ifstream.open()

int main(int argc, char *argv[])
{   ifstream inHandle;
    Assembler obj;
    if(argc!=2)
    {	cout<<"InvalidInput ERROR";
    }
    else
    {   inHandle.open("test.asm");
	if(inHandle==0)
             cout<<"FileNotFound ERROR";
	else
	     obj.pass1(inHandle);
    }
    inHandle.close();
    return 0;
}


this is my code for the main() function, i have tried entering the filename in every possible format but the control always jumps to..

if(inHandle==0)
    cout<<"FileNotFound ERROR";

..Can anyone please suggest me what the problem could be?!?

NOTE: i am using TurboC++ v3.0

shantanusinghal
Newbie Poster
12 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

try using if( inHandle.is_open() )

The problem might also be that the file does not exist in the current working directory.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

try using if( inHandle.is_open() )

The problem might also be that the file does not exist in the current working directory.

[IMG]http://img841.imageshack.us/img841/3268/tempih.th.jpg[/IMG]


* i have tried specifying the complete path at command line
* i have placed the file not just in the right directory but practically every directory

..so its gotta be something else. please HELP me here.

shantanusinghal
Newbie Poster
12 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Try using perror to see if you can get a more informative error message.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Do you have the permissions to read the file/directory ?

Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
 
Do you have the permissions to read the file/directory ?


Ofcourse is do, im logged in as Administrator.

shantanusinghal
Newbie Poster
12 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

bump ^^

and comments or suggestion would be incredibly helpful..

shantanusinghal
Newbie Poster
12 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

try the same program with a more modern compiler, such as Code::Blocks or VC++ 2010 Express, both free. The problem might be that old compiler you are trying to use on MS-Windows operating system.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
bump ^^


Bumping is extremely rude. You're not important enough to justify pushing everyone else down, and one person to page 2.and comments or suggestion would be incredibly helpful..
Did you try my suggestion? Because if not, I'm not going to help any further. You can get a reasonably informative error message with perror because 9 times out of 10, the iostreams library will correctly set errno.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: