-3

I'm trying to make a game in C++ using graphics. I'm using code blocks. I'm trying to make a screen where the player tells his/her name or username. I want to make each letter they press appear but I can't. This is what I've done so far

void user_engleza()
{
    cleardevice();
    while(true)
    {
        char s[101];
        ifstream f("nume.in");
        ofstream g("nume.in");
        bool ok = false;
        char litera[1], nume[101];
        int x, y, j = -1;
        settextstyle(6, HORIZ_DIR, 7);
        outtextxy(300, 100, "Your name will be");
        x = 700;
        y = 150;
        while(ok == false)
        {
            cin >> litera[0];
            g << nume[++j];
            outtextxy(x, y, litera);
            y = y + 100;
            if(GetAsyncKeyState(VK_RETURN)) ok = true;
        }
    }
}

Thank you for help anticipate.

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Which C++ compiler are you using? Turbo C++? If so, add that tag... Also then the answer is... please don't use Turbo C++ unless you really are forced to, because it's not standard C++, and perhaps more importantly, it's not really anything like writing modern C++ should be. So you can learn programming with Turbo C++, but you can't really learn *C++* (except bad practices). – hyde Nov 18 '19 at 08:41

1 Answers1

0

No you can not use BGI for console !!!

BGI uses VGA graphics video modes and MS-DOS console uses VGA text video mode. Those are not the same they even use different segment of memory. For more info see:

In Windows the console is not a text window however its emulation of it. If you get its handle you can access its canvas and render graphical stuff on it but that is not possible with BGI as that is emulation of old BGI window from MS-DOS.

How ever you can render text with BGI on BGI window (no console). To render one character at a time you need to pass a string of length 1 not character. So someting like this:

char c[2]={' ',0}; // null terminanted 1 char string

c[0]='A'; // any character you want
outtextxy(x,y,c);

also y = y + 100; looks like a lot. I would expect y+=20 or similar 100 pixels between characters is too much how big is your window?

Spektre
  • 49,595
  • 11
  • 110
  • 380