Variable that can store letters AND numbers?

I'm making a game, and for the HUD, I need to display the code page 437 characters (I can already do) AND display the variables of the health/xp/whatever, inside the HUD. I sort of have an idea, but it is a little complex, and I want to know if there is a somewhat easier way.
Format a string with your variables, then print them:

1
2
3
4
5
6
7
8
int health = 10;
int exp = 100;
int whatever = 1234;

stringstream s;  // #include <sstream>
s << "Health:  " << health << "  Exp:  " << exp << "  whatever:  " << whatever;

OutputThisString( s.str().c_str() );
Well, im doing it in the format of an array, and each cell is displayed in order.
Strings are arrays:

1
2
3
4
5
6
7
8
9
stringstream s;  // #include <sstream>
s << "Health:  " << health << "  Exp:  " << exp << "  whatever:  " << whatever;

string output = s.str();

for(int i = 0; i < output.length(); ++i)
{
    // output[i] is a character in the string
}


If that's not what you meant, can you clarify more?
If I am getting it right, you can use a struct/class if you want to strore multiple variables in one structure.

struct Stats
{
double health, xp
whatever
}

You can use it as a whole or per struct/class element;

1
2
3
4
Stats S;
S.xp = 100.0;
void set_stats(Stats &S)
{...}
But the classic way of storing multiple data types in the same memory is a union. You could look at VARIANT...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
typedef struct tagVARIANT VARIANT;
typedef struct tagVARIANT VARIANTARG;

typedef struct tagVARIANT
    {
    VARTYPE           vt;        //Identifies the type
    unsigned short    wReserved1;
    unsigned short    wReserved2;
    unsigned short    wReserved3;
    union
        {
        //by-value fields
        short             iVal;
        long              lVal;
        float             fltVal;
        double            dblVal;
        VARIANT_BOOL      bool;
        SCODE             scode;
        CY                cyVal;    //Currency
        DATE              date;
        BSTR              bstrVal;
        IUnknown FAR *    punkVal;
        IDispatch FAR*    pdispVal;
        SAFEARRAY FAR*    parray;

        //by-reference fields
        short FAR*          piVal;
        long FAR*           plVal;
        float FAR*          pfltVal;
        double FAR*         pdblVal;
        VARIANT_BOOL FAR*   pbool;
        SCODE FAR*          pscode;
        CY  FAR*            pcyVal;
        DATE FAR*           pdate;
        BSTR FAR*           pbstrVal;
        IUnknown FAR* FAR*  ppunkVal;
        IDispatch FAR* FAR* ppdispVal;
        VARIANT FAR*        pvarVal;
        void FAR*           byref;
        };
    };

Topic archived. No new replies allowed.