I am using the CStdioFile Class to modify a file.
But when i use the WriteString function it replaces the characters in the file. How can I add content to the file without replacing it.
Or how can i modify a single line alone
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use SeekToEnd function to set file pointer to the end of file. After this call WriteString.
 You must notice that , if the file contents is binary, you must write binary values. When you write a string, the ASCII codes are written.
To write a binary value use:

MyString.Format("%c", x);//x is what you want to write

Then write the string into the file.

Good Luck!
Amritpal SinghCommented:
i think u have to read file in a string
use replace function of that string
and again write the string to the file
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

hey_yuviAuthor Commented:
The problem is that when i write a string it replaces the number of bytes of that string in the file without any concern to what line the text is . eg
the contents of file are

Line 1
Line 2
Line 3
Line 4

Now i move to Line 2 using ReadString functions and then give
WriteString("New Line 2");
then the whole file changes as

Line 1
Line 2
New Line 2

So it replaces string in next line also
How to avoid this

Did you read my comment?
After you use ReadString, the file poiter moves to end of line 2. After using WriteString, the contents are writte over line3. To avoid it, use
Seek function to point to begin of line 2 again.

Good Luck!
hey_yuviAuthor Commented:
 Thanks For ur response.
I think i am bothering u again.
I want to insert a line to the file and not at the end. so i cant use SeekToEnd()

Similarly when my new string's length is greater than the one in the file,
the next line also gets replaced , which i want to avoid.!!

AndyAinscowFreelance programmer / ConsultantCommented:
Create a temporary file.
Read string from file 1, write to temporary file (along with changes).
repeat above line until finished.
delete original file.
rename temporary file to that of the original.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

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.