Using strings in arrays

hello i am rather new to c++ and im wondering if i did this right..

heres the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string>
#include <iostream>
#ifndef CLASSES_H_INCLUDED
#define CLASSES_H_INCLUDED

using namespace std;
class Drawing
{
    public:
    int DrawID[50], sorx[50], sory[50], sorw[50], sorh[50], desx[50], desy[50], desw[50], desh[50];
    char DrawName[50];

    DrawName[0] = "stats.png";
    DrawID[0] = 0; //Stats
    sorx[0] = 0;
    sory[0] = 0;
    sorw[0] = 100;
    sorh[0] = 70;
    desx[0] = 0;
    desy[0] = 0;
    desw[0] = 100;
    desh[0] = 70;

};


i am using SDL to make a game and right now i thought it would be a good idea to make the drawings into arrays to make things faster.


also heres the part where im drawing the rectangles:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int a;
    for(a=0;a=0;a++)
    {
        Drawing Draw[a];
        SDL_Surface* DrawIT[a] = IMG_Load(Draw[a].DrawID[a]);
        SDL_Rect Draw2[a]; //player source 1
        Draw2[a].x = Draw[a].sorx[a];
        Draw2[a].y = Draw[a].sory[a];
        Draw2[a].w = Draw[a].sorw[a];
        Draw2[a].h = Draw[a].sorh[a];

        SDL_Rect Draw3[a]; //player destination 1
        Draw3[a].x = Draw[a].desx[a];
        Draw3[a].y = Draw[a].desy[a];
        Draw3[a].w = Draw[a].desw[a];
        Draw3[a].h = Draw[a].desh[a];
    }



if this is not right please help me out

i would appreciate it


EDIT: also i am using Code::Blocks with MinGW and this is an SDL project if that helps
-Molma
Last edited on
chars have a single character like 's'. "stats.png" is more than 1 character, so it cannot fit in a char.

Instead.. use a string:

1
2
// char DrawName[50];  // boo
std::string DrawName[50];  // yay 



Although... isntead of having all these arrays, it's easier if you put everything in a struct and then have an array of structs:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct DrawInfo
{
    int DrawID, sorx, sory, sorw, sorh, desx, desy, desw, desh;
    std::string DrawName;
};


class Drawing
{
    public:
    DrawInfo info[50];

   // now you have info[0].DrawID, etc
};


Also note you cannot put assignments in the class body like that. Any actual code that is executed belongs in functions, not in class bodies.
Topic archived. No new replies allowed.