Converting Chars to Ints

This is a discussion on Converting Chars to Ints within the C++ Programming forums, part of the General Programming Boards category; I'm doing an assignment in which I have 2 stacks, one for numbers and the other for operators. Both stacks ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    18

    Edit: Solved, thanks, delete if you want to

    I'm doing an assignment in which I have 2 stacks, one for numbers and the other for operators. Both stacks are of the same class and have to both be ints, so when I push an operator in to the Op class, It has to be converted from character to an Int value. The char's for Op are - + * / and %. I'm sure this is something elementary that I've missed, or forgotten. Could someone help with this obstacle?
    Last edited by sycorax; 09-06-2005 at 10:37 PM.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Um do you want a simple cast?
    Code:
    char c = '%';
    //c++ cast
    int a = static_cast<char>(c);
    //or C-style cast...
    a = (char)c;
    Although I don't see why it has to be an int, but whatever.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    18
    thanks alot, ill read more ab out how static_cast works, just antoher knid of typecasting right?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A lottery program - arrays, ints, chars etc
    By Glauber in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2008, 10:48 AM
  2. joining two chars together and converting to INT
    By tehprince in forum C++ Programming
    Replies: 5
    Last Post: 12-21-2007, 01:08 PM
  3. converting ints to chars
    By e66n06 in forum C Programming
    Replies: 4
    Last Post: 07-28-2007, 03:52 PM
  4. atoi not converting chars to ints?
    By C++Child in forum C++ Programming
    Replies: 13
    Last Post: 10-08-2004, 03:59 PM
  5. converting chars to ints
    By nebie in forum C++ Programming
    Replies: 6
    Last Post: 09-01-2001, 11:33 AM

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