Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2190
  • Last Modified:

CFile write problem

I'm trying to write using CFile.

CFile cf(L"C:\\Text.txt", CFile::modeWrite);
cf.Write(m_values, m_values.GetLength());
cf.Close();

When I write out the file it comes out like this:

H e r e   i s   m y   e x a m p l e .

Why isn't it spaced together like normal. If you debug and see the value of m_values, its("Here is my example.").  Why does it come out all funky?
0
cophi
Asked:
cophi
  • 3
  • 2
  • 2
1 Solution
 
cophiAuthor Commented:
m_values is a CString
0
 
jkrCommented:
Open the text file as UNICODE - you are creating a UNICODE version, that's th eproblem.
0
 
DanRollinsCommented:
The other way to go is to avoid using UNICODE.
For one thing you won't need to put L in front of all of your string constants :)

To avoid using Unicode, look in your Project settings.  In the General tab, look to the Preprocessor Definitions... there you will find the word _UNICODE.  That is what is causing the problem.  Remove it and all of your strings will be composed of "normal" 8-bit characters.

Of course, if you expect to sell a Mandarin Chinese version of your program, the UNICODE is the way to go.  Unicode text is also handy if you will be accessing a lot of COM objects.

-- Dan
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jkrCommented:
>>Of course, if you expect to sell a Mandarin Chinese version of your program, the UNICODE is the
>>way to go.

No. UNICODE is the charset of the new century *g*
0
 
cophiAuthor Commented:
Well I do have to use UNICODE.  How do I use CFile with Unicode for writing and reading?
0
 
cophiAuthor Commented:
I figured it out
0
 
DanRollinsCommented:
I was just pointing out the alternative... I've seen lost of programmers confused about issues that there is no need to ever be confused about.  If one does not need Unicode,  why use it?  It just doubles the size of every string of text and complicates things that are otherwise very simple. :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now