CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    Writing in a file using CArchive class

    Hi all,

    I am trying to write into file using CArchive class. I have written a simple code just to open a file using and write into it using CArchive class.

    Code:
    CFile file;CFileException e;file.Open(L"C:\\file.txt",CFile::modeReadWrite,&e);CArchive ar (&file, CArchive::store);char c = 'A';int i = -400;float f = 1.25f;double d = 3.14159265;ar << c;ar << i;ar << f << d;
    but when i open the file the content inside it is

    Apþÿÿ ?ñÔÈSû! @

    Please anybody can tell me what exactly i am doing wrong

    Thanks in advance
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  2. #2
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Lightbulb Re: Writing in a file using CArchive class

    Next time when you post your code in code tags, please dont forget to put linebreaks wherever necessary.. it was hard to read, and i copied your code into a notepad, and put linebreaks to make it readable!


    Anyway, try this...

    Code:
    CFile file;
    CFileException e;
    
    file.Open( _T( "C:\\file.txt" ), CFile::modeCreate | CFile::modeReadWrite, &e );
    char buffer[50];
    memset( buffer, 'A', sizeof(buffer) );
    file.Write( buffer, sizeof(buffer) );         
    file.Flush( );
    "I studied everything but never topped. Today, toppers of the world's best universities are my employees"

    -William Henry Gates (Bill Gates)

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

    Re: Writing in a file using CArchive class

    Why are you using CArchive, what are you using to look at the file and what are you expecting to see?

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