End of File Character

Posted on 1999-12-09
Medium Priority
Last Modified: 2010-04-01
This is a really silly C++ question and im embarassed to ask it, but I cant seem to figure out how to stop it.  I have an output file that i am outputting some CStrings.  When it outputs the CStrings and gets to the last one, my program outputs and end of file character that looks like a 'y' with two dots over it.  So when i read in that file the next time, it reads in that y.  My input file reads in until it gets to the eof character so that is ok, but i dont want the eof character to be visible upon output. How can i do this?Thanks!!!
Question by:epastoor

Expert Comment

by:Jan Louwerens
ID: 2270432
can you post your code?

Expert Comment

ID: 2270480
feel free to ask any tech question, epastoor
i met the same problem months ago, but i forgot how to solve it
i will read my code and try to help you
i am also willing to hear experts' idea about it, coz i am not sure my solution is right

BTW, wait for your code first
LVL 22

Accepted Solution

nietod earned 0 total points
ID: 2270514
You should open the file in binary mode.  If the file is in text mode, the end of file character may be appended automatically when the file is closed.

I'm not sure how you are opening the file, but most likely you are using a fstream objects, if so, just ios::binary in the mode parameter (2nd parameter) of the fstream's constructor.

Let me know if you have any questions.

Author Comment

ID: 2275678
Correct..i am using fstream
i tried adding the binary command and it completely deleted my input file. when my program loads up, i load each string in the input file, string by string.  
here is how i am currently opening the file
fstream inFile;
inFile.open("file.txt", ios::in |ios::out);

any thoughts to what else i could try  so that it didnt print out that character?

LVL 22

Expert Comment

ID: 2304643
Sorry, I did not respond earlier.  I've had terrible computer problems and have been unable to access the internet for over a week!  What's more I am now goign away for a week.  Sorry.

Try adding the ios::app  (append) flag, like

inFile.open("file.txt,ios::in | ios::out | ios::app);

If that doesn't help (it will, but you might have other problems too), I will be back on January 2nd.

sorry again

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question