CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013
    Posts
    1

    Problem about file handling!!!

    Every time I write in file using ofstream it works fine except for one thing that when the file is re-opened after writing something and we try to add more data then previously added data is removed how to get rid of this.

    <code>


    struct abc
    {
    char name[100];
    int a;
    };


    int main()
    {


    ofstream file;
    file.open("text.dat", ios:ut | ios::binary);


    abc x;



    x.a = 2;
    cout<<"Enter name ";
    cin>>x.name;



    file.write((char*)&x,sizeof(struct abc));
    file.close();

    getch();
    return 0;
    }

    </code>

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Problem about file handling!!!

    Code:
    ofstream file;
    file.open("text.dat", ios:app | ios::binary);

Tags for this Thread

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