ifstream

This is a discussion on ifstream within the C++ Programming forums, part of the General Programming Boards category; Code: ifstream nessave("C:/ff1/ff1.ss0", ios:in); i wanna read from my ss0 file (in hex :-) 1 char at a time)...

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    ifstream

    Code:
    ifstream nessave("C:/ff1/ff1.ss0", ios:in);
    i wanna read from my ss0 file (in hex :-) 1 char at a time)

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Try
    Code:
    nessave.setf(ios::hex);
    while (!nessave.eof())
       nessave.get(mychar);

  3. #3
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    ios::hex i believe is the correct parameter....as far as one character at a time, that may be difficult since hex is like this: E0A4B3

    so you may want to toy with that...especially cause 12345678 is hex too.
    PHP and XML
    Let's talk about SAX

  4. #4
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    hex

    Yes but surely if i read one char from the file "!" wouldnt it read it as "21" then?
    Last edited by krappykoder; 12-19-2002 at 09:12 AM.

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Wait, what am I talking about
    Open the file as ifstream nessave("C:/ff1/ff1.ss0", ios::in | ios::binary); and simply read a char in using nessave.get(). Loop until eof is read.

    There, done. Your char can represent from 0 to 0xFF.
    If you read in '!', you can either work with it as 0x21, or 33.

  6. #6
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154
    You make it sound so easy. how do i use get() and should it be a char or int?

  7. #7
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154
    Code:
    ff1.ss0
    
    A B C D E F
    But when i output what ive read it always prints " ".

  8. #8
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Its simple. Open the file in binary mode. Then use ifstream::get() to read a char. Do something like this before you print it:

    cout.setf(ios::hex | ios::showbase | ios::uppercase);
    cout << static_cast<int>(my_char_that_i_read);

    It's all in how you work with it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple ifstream Question
    By Paul22000 in forum C++ Programming
    Replies: 8
    Last Post: 12-05-2008, 05:34 PM
  2. store data from ifstream and store in link list
    By peter_hii in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2006, 09:50 AM
  3. ifstream
    By Wraithan in forum Tech Board
    Replies: 3
    Last Post: 09-24-2006, 02:26 AM
  4. ofstream and ifstream for searching and writing
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-17-2003, 08:34 AM
  5. Ifstream Problems
    By IlUomo in forum Windows Programming
    Replies: 1
    Last Post: 04-24-2002, 01:51 PM

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