CStdioFile Possible bug

Hey I use the CStdioFile object to write certain strings to a text file

When i use the WriteString method to write the following string " This is a test " the string is not output it seems to be because of the " "character, it is charcter 24. Does anyone know why this is doing this?

Thanks

Will
[324 byte] By [wdhough] at [2007-11-20 6:32:18]
# 1 Re: CStdioFile Possible bug
Hey I use the CStdioFile object to write certain strings to a text file

When i use the WriteString method to write the following string " This is a test " the string is not output it seems to be because of the " "character, it is charcter 24. Does anyone know why this is doing this?

Thanks

Will

What the problem you got, it should work fine.
Show the code which is causing you the problem.

Thanx
dwurity at 2007-11-10 23:01:12 >
# 2 Re: CStdioFile Possible bug
ok sure, The problem i have is no string is printed out to the file. If i remove the " " character (Character 24) then the string does display.

Heres my code:

CString name = _T("C:\\testingquote.txt");
CStdioFile file;
if ( !file.Open ( name, CFile::modeCreate|CFile::modeWrite))
return;

CString str = _T(" This is a test ");
file.WriteString(str);
file.Close();

I also tried this but got the same result

CString name = _T("C:\\testingquote.txt");
CStdioFile file;
if ( !file.Open ( name, CFile::modeCreate|CFile::modeWrite))
return;

CString str = _T("This is a test");
str = char(24)+str+char(24);
file.WriteString(str);
file.Close();

Thanks for your help
wdhough at 2007-11-10 23:02:12 >
# 3 Re: CStdioFile Possible bug
ok sure, The problem i have is no string is printed out to the file. If i remove the " " character (Character 24) then the string does display.

Heres my code:

CString name = _T("C:\\testingquote.txt");
CStdioFile file;
if ( !file.Open ( name, CFile::modeCreate|CFile::modeWrite))
return;

CString str = _T(" This is a test ");
file.WriteString(str);
file.Close();

I also tried this but got the same result

CString name = _T("C:\\testingquote.txt");
CStdioFile file;
if ( !file.Open ( name, CFile::modeCreate|CFile::modeWrite))
return;

CString str = _T("This is a test");
str = char(24)+str+char(24);
file.WriteString(str);
file.Close();

Thanks for your help

Please use the code tags when you post your code for the next time.

Ok when comes to your problem, the code which you gave is working fine in my machine, are you sure you are checking the correct file.

Thanx
dwurity at 2007-11-10 23:03:16 >
# 4 Re: CStdioFile Possible bug
Yep i'm sure, any other ideas?

what are the code tags, people have said that to me more than once but i dont know what they are.
wdhough at 2007-11-10 23:04:16 >
# 5 Re: CStdioFile Possible bug
Yep i'm sure, any other ideas?

Write one sample application and test whether its working or not.

what are the code tags, people have said that to me more than once but i dont know what they are.

simple, your code should enclose your code inside the 'code' tags

See the below link.

http://www.dev-archive.com/forum/misc.php?do=bbcode#code (Code Tags)

Thanx
dwurity at 2007-11-10 23:05:15 >
# 6 Re: CStdioFile Possible bug
Try some other way of writing it to file, like using STL class ofstream or CRT fwrite etc for the same string.
Krishnaa at 2007-11-10 23:06:09 >
# 7 Re: CStdioFile Possible bug
you should use [code] and its closing tag with a forward slash before "code".

=Dan
danandu at 2007-11-10 23:07:13 >
# 8 Re: CStdioFile Possible bug
I also didn't got any error for this

CString name = _T("C:\\testingquote.txt");
CStdioFile file;
if ( !file.Open ( name, CFile::modeCreate|CFile::modeWrite))
return;

CString str = _T(" This is a test ");
file.WriteString(str);
file.Close();

STrange!:rolleyes:
danandu at 2007-11-10 23:08:11 >
# 9 Re: CStdioFile Possible bug
You should really learn how to use a debugger if you don't know how to use it yet. It will help to make you a good programmer.
miteshpandey at 2007-11-10 23:09:14 >
# 10 Re: CStdioFile Possible bug
HI,

I took your advice and build a sample app. The output is " This is a test "

Which might not be right but is definately different, so could this be down to me project settings, i am not available of any change that could do this.

I will debug into the WriteString method as well. But i do generally debug

Will
wdhough at 2007-11-10 23:10:15 >
# 11 Re: CStdioFile Possible bug
I have noticed the special character u use "`" is a little curved so it couldn't be identified in the ANSI character set. So change your project settings to the UNICODE environment and it should be alright. I hope so.
miteshpandey at 2007-11-10 23:11:19 >
# 12 Re: CStdioFile Possible bug
Ok,

I have played around with the "Character Set" setting in my sample application if I set it to "Use Unicode Character Set" it DOESNT work. However if i set it to "Use Multi-Byte Character Set" it DOES work. How strange.

Yes your right about the curlyness, it doesnt come out so well in the in the forum. If you load MS word and type 'This is a test' you will see the character i mean

I have uploaded my sample app to show this. I guess this is one of the many unicode/ansi/multi-byte issues.

Doh!
wdhough at 2007-11-10 23:12:23 >
# 13 Re: CStdioFile Possible bug
When you use different character sets, you should use TCHAR not char, and all the other macros with T. Take a look at this FAQ ( http://www.dev-archive.com/forum/showthread.php?t=404079).
cilu at 2007-11-10 23:13:19 >
# 14 Re: CStdioFile Possible bug
I think it is becuase due to the difference in UTF encoding format in MS-WORD and visual Studio as you ported thouse two opening and closing character from MS-WORD
miteshpandey at 2007-11-10 23:14:20 >
# 15 Re: CStdioFile Possible bug
You should really learn how to use a debugger if you don't know how to use it yet. It will help to make you a good programmer.

I would say, it will help you become a programmer. ;)
Krishnaa at 2007-11-10 23:15:23 >