fstream read() question.

This is a discussion on fstream read() question. within the C++ Programming forums, part of the General Programming Boards category; Ok I have an array Code: unsigned char Memory[0xFFF]; I want to load a file into this memory, but I ...

  1. #1
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    fstream read() question.

    Ok I have an array
    Code:
    unsigned char Memory[0xFFF];
    I want to load a file into this memory, but I want it to start at 0x200, not at the beginning of the array.

    Here's my code

    Code:
    bool CPU::LoadRom(char *sFileName)
    {
      ifstream Rom(sFileName);
    
      if(!Rom.is_open())
        return FALSE;
    
      Rom.seekg(0, ios::end);
      long size = Rom.tellg();
      Rom.seekg(0, ios::beg);
    
      Rom.read(Memory, size);
    
      Rom.close();
      return TRUE;
    }
    How can I start reading in at 0x200?

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    The simplest way I could think of would be to read the data into a smaller array (0xFFF - 0x200 - I'm too tired to do the arithmetic) and then read the data from that array the latter part of Memory[]

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Ok thanks I'll try that. Dont know why I didnt think of that.

    But If anyone knows of a different way, let me know.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I want to load a file into this memory, but I want it to start at 0x200, not at the beginning of the array.

    Rom.read(Memory+0x200, size);

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Rom.read(Memory+0x200, size);

    lol, i must be sleepy. I always seem to miss the simplest things
    Thank you.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    That's one thing which makes the C/C++ language unique. You can do cool stuff like that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pico vs Vi(m) read lock question
    By Overworked_PhD in forum Linux Programming
    Replies: 1
    Last Post: 06-29-2009, 07:38 AM
  2. "sorting news" assignment
    By prljavibluzer in forum C Programming
    Replies: 7
    Last Post: 02-06-2008, 06:45 AM
  3. read binary image w/ fstream?
    By new90 in forum C++ Programming
    Replies: 2
    Last Post: 12-11-2005, 07:59 PM
  4. Replies: 3
    Last Post: 11-03-2003, 04:43 PM
  5. DirectX question, please read!
    By Crossbow in forum Game Programming
    Replies: 2
    Last Post: 12-12-2001, 07:18 PM

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