Thread: Char to Hex

  1. #16
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    That's it... I'm downloading Dev-C++

  2. #17
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    lol

    Thank you lol

    Knowing my luck it'll be some msyterious dev bug and ill have to change compiler

  3. #18
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Code:
    #include <iostream.h>
    
    int main ()
    {
    	char c = 'ÿ';
    	cout.flags(ios::hex | ios::showbase);
    	cout << int(c);
    	
    	return 0;
    }

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

    source

    Argh recommend any good win compilers?

  5. #20
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Yes, Visual C++

    The code works now right? I'm such an idiot!

  6. #21
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    :)

    dude ure the gr8est

  7. #22
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    No, I told you... I'm an idiot!

  8. #23
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    1 last thing

    last thing how do i check if file opens correctly?

  9. #24
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    hmm, well you first have to open the file. Then do this:
    Code:
    if(file.fail())
       //whatever you do if it fails
    Or it could be file.error or something; I'm not sure. But if you're just checking if the file didn't exist, you have to call 2 error checker thinger functions (if one says there's an error, you have to check the other one; if the other one says there's no error, it means that it's a small error such as file not found. Otherwise, you're in deep doodoo! )

    Actually, I might be wrong... maybe you can directly check the error flags, but I'm too lazy to figure it out myself; you'll have to ask bmj
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #25
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    If the .open() fails, the return is NULL, so you can do this:
    Code:
    #include <fstream.h>
    
    int main ()
    {
    	ifstream ifile;
    	
    	ifile.open("NotThere.txt", ios::in);
    	
    	if (!ifile)
    	{
    	    cout <<"Error" <<endl;
    	    return 1;
    	}
    	
    	ifile.close();
    	
    	return 0;
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #26
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Oh right, lol how could I forget the obvious?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #27
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Originally posted by Hunter2
    Oh right, lol how could I forget the obvious?
    drugs?

  13. #28
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    errors

    Code:
    switch(int(buf))
    {
    case 0x8A: file1<<"A";
    break;
    default: file1<<int(buf);
    break;
    }
    Thats the code i would like to use but it doesnt work.
    The program should:
    Check to see what the read char was if and save it as diff char depending of what was read.
    i really dont wanna make a varirable containing all 50odd cases i have.

  14. #29
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    Code:
    cout << hex < i
    that outputs i to the screen in hexadecimal. nice and clean. you nead iostream... I don't think it matters if you have the .h or not

  15. #30
    What about binary or octal?

    cout << binary << 'h'
    cout << octal << 'G'

    ???
    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. Replies: 12
    Last Post: 08-11-2008, 11:02 PM
  3. lvalue error trying to copy between structures
    By emanresu in forum C Programming
    Replies: 2
    Last Post: 11-16-2006, 06:53 AM
  4. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  5. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM