structures, pointers to structures, and the write() member function

This is a discussion on structures, pointers to structures, and the write() member function within the C++ Programming forums, part of the General Programming Boards category; Hello Everyone!!! I have a serious problem. I know this may sound a bit amateurish, but I am really stuck. ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Unhappy structures, pointers to structures, and the write() member function

    Hello Everyone!!!

    I have a serious problem. I know this may sound a bit amateurish, but I am really stuck. I have a dynamically allocated array of structures, and have to print it to a file using binary output. The problem is I keep getting a "Stack Exception" error in the "Write(1)...memorey address". Here is my current code:

    outbin.write((char *)studRecPtr, sizeof(studRecPtr[loopIt]));

    Any help would be highly appreciated. Thank you.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: structures, pointers to structures, and the write() member function

    Originally posted by 9933515
    Hello Everyone!!!

    I have a serious problem. I know this may sound a bit amateurish, but I am really stuck. I have a dynamically allocated array of structures, and have to print it to a file using binary output. The problem is I keep getting a "Stack Exception" error in the "Write(1)...memorey address". Here is my current code:

    outbin.write((char *)studRecPtr, sizeof(studRecPtr[loopIt]));

    Any help would be highly appreciated. Thank you.
    You could try:

    outbin.write((char*)studRecPtr, NrOfStructs * sizeof(STRUCTBASE));

    if you have typedef:ed your struct

    typedef struct
    {
    ...
    }STRUCTBASE;

    STRUCTBASE* studRecPtr;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    how does this write function work?
    what header?

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    fstream.h, I believe...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try:

    outbin.write((char *)studRecPtr[loopIt], sizeof(studRecPtr[loopIt]));

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    2
    i figured it out!!!!!! thanks for your help!!!!!

Popular pages Recent additions subscribe to a feed

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