Thread: problem with file

  1. #1
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118

    problem with file

    what is the problem with this program?

    Code:
    #include<iostream>
    #include<fstream>
    using namespace std;
    enum flag {no=0,yes=1};
    int main()
    {
        flag setflag=no;
        fstream myfile("d:/hsys.dll",ios::binary);
        myfile.write((char *)&setflag,sizeof(flag));
        if(!myfile)
        {
            cout<<"operation failed!!\n";
            return 0;
        }
        return 0;
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    The mode should be ios::out | ios::binary at least. Since the mode is just a number, if you have to provide a mode, provide the right number, or it won't work.
    Last edited by whiteflags; 06-12-2011 at 11:05 PM. Reason: remove smilies

  3. #3
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    yeah it worked. the program is now running.
    but should it have something written inside it. I mean if I open it in note pad. some ascii chars are ought to present in it. But they are not.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Since you are printing the number 0 or the number 1, which are non-printing control characters you will not see them in notepad.

    Jim

  5. #5
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    Thanks a lot.
    :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data file problem use FILE, loop, and if-else
    By Cyberman86 in forum C Programming
    Replies: 3
    Last Post: 03-25-2009, 10:52 PM
  2. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  3. Replies: 3
    Last Post: 11-21-2006, 07:26 PM
  4. Replies: 3
    Last Post: 10-20-2006, 07:59 PM
  5. Replies: 3
    Last Post: 05-03-2003, 12:04 PM