Thread: Help with ifstream read plz

  1. #1
    dp_goose
    Guest

    Question Help with ifstream read plz

    I have written to a binary file using the following
    Code:
    m_fpFileOut.open(szFilename,ios::out|ios::binary|ios::app);
    
    m_fpFileOut.write((char *) &m_wHeader,sizeof(trUInt16));
    m_fpFileOut.write((char *) &m_kDate.m_bDay,sizeof(trUInt8));
    m_fpFileOut.write((char *) &m_kDate.m_bMonth,sizeof(trUInt8));
    m_fpFileOut.write((char *) &m_kDate.m_wYear,sizeof(trUInt16));
    The file looks like what I expect but when I try to read in the file using:
    Code:
    m_fpCallData.read((char *) &m_wHeader,sizeof(trUInt16));
    m_fpCallData.read((char *) &m_kDate.m_bDay,sizeof(trUInt8));
    m_fpCallData.read((char *) &m_kDate.m_bMonth,sizeof(trUInt8));
    m_fpCallData.read((char *) &m_kDate.m_wYear,sizeof(trUInt16));
    printf(">%d<\n",m_wHeader);
    printf(">%d<\n",m_kDate.m_bDay);
    printf(">%d<\n",m_kDate.m_bMonth);
    printf(">%d<\n",m_kDate.m_wYear);
    m_wHeader get populated correctly but the others remain at the values that I initialized them with.

    Any ideas ?

    Thanks

    Goose

    &#91;code]&#91;/code]tagged by Salem

  2. #2
    dp_goose
    Guest

    Angry Got it

    I had a failure earlier on when trying to open files and the fial bit was set. Forgot to reset it.


    4 hours of my life waisted. DOH !!!

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Got it

    >>4 hours of my life waisted. DOH !!!
    Only 4 hours... that's not too bad
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [question] ifstream read file, thanks!
    By userpingz in forum C++ Programming
    Replies: 6
    Last Post: 05-19-2009, 06:38 PM
  2. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. I am lost on how to read from file and output to file?
    By vicvic2477 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2005, 11:52 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM