display width and height allegro

what is the difference between doing

using namespace std;

cout << "bla bla bla";

and

std::cout << "bla bla bla";

and why do people say that std:: is better then using namespace?

also, what is a better way to make the console window stay shown in the following code? i know it is bad to use system("well_anything_really"); but that what i knew would fix the problem.

without it the console did not show and it would display a window with no size. just the bar on top (name, minimize button, unavailable max button, exit)

how can i fix this?

i am learning allegro5 and have written a simple program. it starts with a console box and asks the user to type the width and height and then it displays an all white window of the given size and a line of text that also states what the size is. it works out well.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>

#include <iostream>

using namespace std;
 
int main(void)
{
    int width;
    int height;
    
    cout << "please enter the width and height of your window: ";
    cin >> width;
    cin >> height;
    
    //system("PAUSE"); figured out how not to use this
    
    ALLEGRO_DISPLAY *display = NULL;
   
    if(!al_init())
    {
         return -1;
    }
   
    display = al_create_display(width, height);
   
    if(!display)
    {
         return -1;
    }
    
    al_init_font_addon();
    al_init_ttf_addon();
    
    ALLEGRO_FONT *font16 = al_load_font("couri.ttf", 16, 0);
    
    ALLEGRO_FONT *font32 = al_load_font("couri.ttf", 32, 0);
    
    al_clear_to_color(al_map_rgb(255, 255, 255));
    
    
    al_draw_textf(font16, al_map_rgb(255, 0, 255), 25, 25, 0, "Width: %i / Height: %i", width, height);
    
    al_flip_display();
   
    al_rest(3.0);
   
    al_destroy_display(display);
   
    return 0;
}


Last edited on
oh. never mind about the system("pause");

i figured it out. just needed to change the project type to win32 console and it worked out just fine with out it.
ok now i am just posting for the sake of posting.

am i on the right track? i feel that learning this is coming along fairly well.
i found that for the line of text i have 300x50 is a good size minimum so nothing gets cut off. so i made the computer prevent any numbers from being input that are lower then 300x50

i also allowed the user to set how long the window stays open for.

any comments? am should i be doing anything different? thanks a lot for the help.






#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>

#include <iostream>

using namespace std;

int main(void)
{
int width;
int height;
int time;

cout << "please enter the width and height of your window(atleast 300x50), and a display time(in seconds): ";
cin >> width;
cin >> height;
cin >> time;

ALLEGRO_DISPLAY *display = NULL;

if(!al_init())
{
return -1;
}

if(width < 300)
{
width = 300;
}
if(height < 50)
{
height = 50;
}

display = al_create_display(width, height);

if(!display)
{
return -1;
}

al_init_font_addon();
al_init_ttf_addon();

ALLEGRO_FONT *font16 = al_load_font("couri.ttf", 16, 0);

al_clear_to_color(al_map_rgb(255, 255, 255));


al_draw_textf(font16, al_map_rgb(255, 0, 255), 25, 25, 0, "Width: %i / Height: %i", width, height);

al_flip_display();

al_rest(time);

al_destroy_display(display);

return 0;
}
Last edited on
Topic archived. No new replies allowed.