Hi guys, I'm trying to write a program that reads from a file using seekg/seekp.
I'm just working on menu option #1 first to simply read from the file and display and I can't seem to get the data to display. I am, however, getting the line "Reading contents from the file below:", but no data from the actual file.
text file is in the same location as source code on the E: drive.
When I try to read a txt file, the data doesn't appear on the console, but when I go to look at the file in the directory after I've tried to run the file it appears like it's now junk ?? see pre and post below. WTH? Any ideas?
1. why won't my file contents display on the console?
2. what in the world is happening to my data after I run the program?
Text file before running the program:
Terri Pinon 123123 100.00 20 4030.00 201.50 604.50 80.60 3143.40
John Smith 11111 50.00 15 2022.50 101.13 303.38 40.45 1577.55
Jane Doe 555555 50.00 10 2015.00 100.75 302.25 40.30 1571.70
Kate Jones ABC123 40.00 10 1615.00 80.75 242.25 32.30 1259.70
Lynn Jackson 121212 30.00 10 1215.00 60.75 182.25 24.30 947.70
After running the program (with data never appearing in the console):
ØS 137
ìS ‰ 2490368
ØS 2653656 &
%à¦~ °[& 2292872
Ä 1994415412 à
à}( 1994415459 Ï
ëS 2124866097 (
² &áÜvñdþÿÿÿc]àvpZàv@ 0
þÿÿÿ @ 2502284
2490368
pZàv ý" 2501936
à}( 0
0
¼ý" T`ßv 2501936
þÿÿÿ 1994362564
àS 2502208
͘Ðv 2147352624
7iàvðS 2488
ùÐvC®ÐvÐþ" 2147344384
ÕŒÒv„ ¦ZþÿÿÿÚ˜Ðvú ÑvPayrollProgram2.txt 4]àvPS 2501936
There was originally writing to the file, but then was just simplified to read for now. I'll remove it. I didn't think it was in the way and had planned to remove it before I was done. Do you think that is causing my issues?
Definitely that was the cause. When I ran the program, as soon as OutList was opened, all data from the original file was lost, which is the default behaviour unless you open it in some specific mode such as append etc.
So I'm trying option 2 now trying to read the file backwards from the last character, but I'm not getting data displayed to the console.
in the last function I set the read position to the end of the file, then get that byte, then go back one position and get that byte, etc. Could it have something to do with reopening the file? I think I handle that with the .fail() at the start of the function. Thoughts?
If the file has already been opened successfully, the only thing required is this:
inFile.clear(); // reset all error flags
Though to be honest, your approach seems like an awful lot of hard work.
I'd just read the entire file line by line into an array, and then display the array in the required order.
unfortunately, i can't use arrays for this assignment. :( just learning to use seek and tell, etc. I'll clear those suspicious lines and replace with clear to see if that helps.