mardi 1 août 2017

wrong values outputted from enum

I'm trying to use the (char) enum to store my ranks and then output them using cout but its not getting out correctly.

#include <iostream>

using namespace std;    

enum rank : char {
    first = '1', second = '2', third = '3'
};

int main()
{
    // other code ...
    cout << rank::third;
    // other code ...
}

It outputs 51 !!! look here - http://ift.tt/2tVjWYJ

This looks like ascii values(?) so should I caste them back to char or some other type (why do I need to do so when I've already written char against that enum), otherwise what is wrong here?

Aucun commentaire:

Enregistrer un commentaire