Ifile.get() is returning a space (' ')

Hello! My name is Matt.

Disclaimer: Don't mind my primitive syntax; there is a limited amount of C++ that I actually know.

Preface: I have a function that goes through a .txt and finds a certain line. I do this by formatting my .txt very specifically (as below).

[encriptions.txt] //not actually encripted ... yet
1
2
3
4
5
6
00
basepassword;password 
ext1:ex 
ext2:mr 
ext3:nj 
ext4:tt 

The '00' and the ';'/':' are used on other parts of the program.
Note the ' ' at the end of each line after the first.

Goal: to print out a numbered list of the password titles only (success) and prompt the user to remove one, confirm that the user is removing the correct one (where my code goes awry), and finally remove it (didn't get there yet).

Ifile.seekg(4L,ios::beg); gets me to the beginning of the second line (base ...)
and I use it for a while loop with Ifile.get(x); (x is a declared char) to cout<< successfully. The user is them prompted for the one to remove. This all works very well.
To comfirm the choice, I want to have a statement say "Really remove xxxxx from the list?" I use Ifile.seekg(4L,ios::beg) again, and Ifile.get(x); to navigate in the file to the beginning of the line with the user's choice in it. Ifile.tellg(); returns a 4 so I know the seekg() is working. The problem now is all of the Ifile.get(x); used after the list is printed return as spaces (' '). This has baffled me, two professors, and several savvy friends of mine.

Things I've tried
- closing and opening the file again
- cout<<ing the value of x at decisive points to confirm that Ifile.get(x); always reutns a space.
- I've tried using Ifile.sync(); to flush the buffer, failed (yielded -1)
- Google has not been of much help, with the exception of it landing me here

Because I really can't advance the program until I get past this, I will be checking this several times a day, so don't be a afraid to ask for more info. If seeing the function would help, I'll gladly post it up. I'll keep it updated as well.

Thanks in advance,
Matt
Last edited on
Well, I suppose you could try getting the entire file into a vector, then doing the file operations on that vector instead of the file. Then after you have all the data, just overwrite the file with the new data.

Also, have you tried checking the .error() bit to see what it is returning? It could be there is a problem with the buffer or something...(I hope there is an .error() bit XD)
... well, because I'm so new to programming, I haven't gotten in to vectors yet. If I can't get fstream to work, I'll have to look into using learnig and implementing vectors for this function.

Ifile.error(); returned a complier error (it doesn't work with Dev-C++ apparently or the compiler ... idk, I'm new to this)

I tried Ifile.bad(); and it yeilded a 0, so I'm assuming it's not bad. The file also made it throught my Ifile.fail(); statement when I opened it.

The buffer seems likely, but I tried Ifile.sync(); and I got a -1 ... not really sure what that means.
Topic archived. No new replies allowed.