problem with file

This is a discussion on problem with file within the C++ Programming forums, part of the General Programming Boards category; what is the problem with this program? Code: #include<iostream> #include<fstream> using namespace std; enum flag {no=0,yes=1}; int main() { flag ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    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-13-2011 at 12:05 AM. 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
    2,919
    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, 11: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, 08:59 PM
  5. Replies: 3
    Last Post: 05-03-2003, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21