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

    Question New to foundation class : CArchive

    I use CArchive to store a string
    into a file

    But I always get an odd character (a square shaped) on top of the file,
    --------

    Cfile f("t.txt",Cfile::modecreate|cfile:modewrite);
    CArchive ar(&f,carchive::store);

    Cstring s="show me the square";
    ar<<s;

    --------

    Could you help me please ?

    Thank you

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: New to foundation class : CArchive

    CArchive doesn't write text files. It adds other information in there. Use CStdioFile if you want to write plain text.

  3. #3
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: New to foundation class : CArchive

    When writing a CString with CArchive, the length of the string is also written to the file. This is done so that the CArchive::Load will know the size.

    If you have MBCS character set used, you'll see the length as the first byte (if the string is less than 254 characters) - so that's the square that you see.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: New to foundation class : CArchive

    There is no need to over complicate the things. Use CStdioFile.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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