File write Problem

I am trying to have a function that when ever I call it it writes a certain set of text to the file. For some odd reason when ever I try to insert "](" string the file gets messed up.

This it the original code.
1
2
3
4
5
fRecord << '[' << LongToString(GetRValue(COLOR2)) 
<< ',' << LongToString(GetGValue(COLOR2)) 
<< ',' << LongToString(GetBValue(COLOR2)) 
<< "](" << LongToString(X) 
<< ',' << LongToString(Y) << ')';


The LongToString function is just a function I made to change a long integer to a string object and the GetRValue and such just extracts a RGB color value from a COLORREF object.

It should turn out to [255,255,255](0,0)[255,255,0](100,100) in the file. However I end up with ㉛㔵㈬㔵㈬㔵⡝ⰰ⤰㉛㔵㈬㔵〬⡝〱ⰰ〱⤰.

when I delete one or both of the ]( charaters from the insert statment it works fine just with the missing charater.

For instance when I use this code.

1
2
3
4
5
fRecord << '[' << LongToString(GetRValue(COLOR2)) 
<< ',' << LongToString(GetGValue(COLOR2)) 
<< ',' << LongToString(GetBValue(COLOR2)) 
<<  LongToString(X) 
<< ',' << LongToString(Y) << ')';


I get [255,255,2550,0)[255,255,0100,100). It seams when I insert the charater combination of ]( it messes up. I have tried inserting them individualy and separating them in seperate sentences and I still does the same thing. Does anyone know what is going on.
Last edited on
Oh, everything is fine with your code. It is just your notepad program autodetecting codepage function messes up. Try to create textfile, paste line
[255,255,255](0,0)[255,255,0](100,100)
there, save and reopen. You will find that it is notepad fault. If you are using Win7 that error should not present in standard windows one, but I use Notepad2 and I got this error when I pasted that text.
That did not work and I am using the Windows xp notepad. But I figured out part of the problem. For some odd reason when I try to insert those charaters it saves the file in Unicode when it is suppose to be in ANSI. The file that got saved without those charaters was ANSI like it was suppose to. I tried to save the strange file as ANSI and notepad gave me a warning saying data could be lost and I ignored it and opened it and all that showed up was question marks.
You were right to a point. The text was right it was just notepad was interperting the text as Unicode for some odd reason. I opened it in wordpad and it showed up correctly.
I managed to solve the problem. The files I am saving usually have a little prefix at the beginning to show some information about the file. I just have it so when the file is created it puts in a default and now the file save right. I think the patern of [data,data,data] notepad was interpereting as a unicode format. I add this !-1,-1) to the beginning and it solves the problem. I just need to make sure the program I am making ignores that front part.
Topic archived. No new replies allowed.