|
-
May 27th, 2008, 10:20 AM
#1
fstream file.open
Hello all,
I have an invoice sort of program. The user enters in a command, and then a product and price, another command to enter in the product and its quantity. They then do a command to generate the invoice.
Part of what i want to do is read in from a file. Now currently, i have got it doing this, if and only if, it is the users first attempt at reading the file in.
here is my code. It should be noted that the user can type in any sequence of program commands (all starting with /), as long as product and it's prices (raw prices) are done first. Like i said this all works.
Now the problem.
If the user ran the program and typed in
/read input.txt and input.txt existed all would be sweet
but if they went
/read bat.txt //bat.txt doesn't exist
*here an error message saying such a file doesn't exist correctly appears*
/read input.txt //input.txt does exist
an error message would appear saying that the input.txt file doesn't exist.
I am at a complete loss as to what is happening. I suspect it has something to do with the first file not being closed down properly, but i have placed that file.close() everywhere i can think of with no results.
Any helpful suggestions please?
thanks all
tim
Last edited by Timmeh041; May 27th, 2008 at 10:39 AM.
-
May 27th, 2008, 10:35 AM
#2
Re: fstream file.open
You probably need to explicitly clear the error condition flag in the stream object.
file.clear() should do it.
-
May 27th, 2008, 10:38 AM
#3
Re: fstream file.open
Lindley, if it were possible to give you a child, i would. Sadly, i am a man. Thank you so very much. Now i can go to bed.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|