turbo-c++conio

Function window() from conio.h doesnt work


I'm using turbo c++ which launches DOSBox 0.74

I have the following program:

#include <conio.h>
#include <stdlib.h>

int main() {
  clrscr();
  window(100, 100, 200, 200);
  textcolor(3);
  textbackground(6);

  cprintf("Hello world");

  getch();

  return 0;
} 

It works and it's pretty same copy from 2 sites, except, it dont make the window. window (100, 100, 200, 200) should make a window with coordinates (100, 100) and (200, 200) from top left corner, but it doesn't happen and text just printed at most top left corner. I didn't find anyone with same problem. Instead tutorial sites shows this example and even screenshots as working.

Did anyone met this problem?


Solution

  • The window() function from conio.h only defines an active window on the text screen. The default screen will be the 80x25 text screen. The coordinates that you specified in window(100, 100, 200, 200); are offscreen, so no window got created.
    Try this:

    window(10, 7, 50, 19);
    gotoxy(16, 7);
    cputs("Hello World");
    

    For a graphical HelloWorld program, you would need to include graphics.h and setup a graphics video mode using detectgraph(), initgraph(), ...