CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2001
    Posts
    251

    Question Appending Unicode text?

    I'm using this to append Unicode text:
    Code:
    FILE *File = _wfopen( filepath, L"at,ccs=UNICODE" );
    This works fine when the Unicode file exists.

    However, sometimes the file might not exist, and the Unicode text gets appended without re-creating the
    BOM mark at the beginning of the file, which corrupts the file.

    Is this how it's suppose to work, or it is a bug?

    I don't understand why append mode doesn't just re-create the mark for non-existent files.

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Appending Unicode text?

    The BOM is not automatically created.
    You will have to write the it yourself at the begining of the file.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Nov 2001
    Posts
    251

    Re: Appending Unicode text?

    Quote Originally Posted by _Superman_ View Post
    The BOM is not automatically created.
    You will have to write the it yourself at the begining of the file.
    Thanks for the reply. That's a bummer!

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Appending Unicode text?

    Before opening, you can check whether the file exists. If it doesn't exist, you create it, write the BOM and close. Then you proceed with the rest of the your code.

    Or you can create your own function, that does all that, and call it instead of each _wfopen call.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured