Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC Problem with writing file

MFC Problem with writing file

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mihai123
    wrote on last edited by
    #1

    Hello , I use this section to write some code in a file f.Open(_T("file.log"), CFile::modeNoTruncate | CFile::modeWrite); if(f!=f.hFileNull) { f.SeekToEnd(); } else { f.Open(szFilename, CFile::modeCreate | CFile::modeWrite); } CArhive arStore(&f, CArchive::store); arStore.WriteString(_T("message"); It works fine like this. But I want to make a class that writes the file. In .h I have : private: CFile f; CArchive arStore; And I have a method to write an open file. I encounter a problem in constructing the arStore object. (ERROR: CArchive not apropiate default constructor available) This like is the problem : arStore(&f, CArchive::store); I think that there is a method like Open for CFile but I don't find it. Tnx for the help

    N 1 Reply Last reply
    0
    • M mihai123

      Hello , I use this section to write some code in a file f.Open(_T("file.log"), CFile::modeNoTruncate | CFile::modeWrite); if(f!=f.hFileNull) { f.SeekToEnd(); } else { f.Open(szFilename, CFile::modeCreate | CFile::modeWrite); } CArhive arStore(&f, CArchive::store); arStore.WriteString(_T("message"); It works fine like this. But I want to make a class that writes the file. In .h I have : private: CFile f; CArchive arStore; And I have a method to write an open file. I encounter a problem in constructing the arStore object. (ERROR: CArchive not apropiate default constructor available) This like is the problem : arStore(&f, CArchive::store); I think that there is a method like Open for CFile but I don't find it. Tnx for the help

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      mihai123 wrote:

      I encounter a problem in constructing the arStore object. (ERROR: CArchive not apropiate default constructor available)

      You can use the Initialization list. eg:

      class Test
      {

      private:
      CFile f;
      CArchive arStore;
      public:
      Test():arStore(&f, CArchive::store)
      {
      };
      };

      nave [OpenedFileFinder]

      M 1 Reply Last reply
      0
      • N Naveen

        mihai123 wrote:

        I encounter a problem in constructing the arStore object. (ERROR: CArchive not apropiate default constructor available)

        You can use the Initialization list. eg:

        class Test
        {

        private:
        CFile f;
        CArchive arStore;
        public:
        Test():arStore(&f, CArchive::store)
        {
        };
        };

        nave [OpenedFileFinder]

        M Offline
        M Offline
        mihai123
        wrote on last edited by
        #3

        tnx it works :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups