I have recently been doing an assignment which had us making a text editor. What I was trying to do is to get the terminal screen size so that I could use the coordinates. Can somebody tell me how I can save the environmental variables as integer values? I googled to find that there is a function use_env for getting the screen size. Can anybody write me a small function as an example to better understand how it works? Also, does anybody know what is the Windows version of ncurses for it does not work with windows?

9 Years
Discussion Span
Last Post by sid78669

If you're using windows, here's a pretty straightforward solution to retrieving the console buffer size.

#include <windows.h>
#include <iostream>

int main()

  int ret = GetConsoleScreenBufferInfo(
    GetStdHandle( STD_OUTPUT_HANDLE ),
    &csbi );

  if ( ret ) {

    std::cout << "Console Buffer Width: " << csbi.dwSize.X << std::endl;
    std::cout << "Console Buffer Height: " << csbi.dwSize.Y << std::endl;


  return 0;			

Hope this helps.


thanks! it helped alot on windows. but is it the same for ncurses on unix?


No -- that code is MS-Windows specific.

ncurses for MS-Windows only works with console programs, not GUI programs. If you want a gui program that is portable to both *nix and windows then don't use ncurses but use something like wxWidgets (there are others too)


i only need to create a console version. So far the best I could do is limit the editors screen to 20x60, so they dont go beyond these. I'm still trying to figure out how to get the current terminals screen size and save them as int. The above state method is only good for windows, as it did not work on Unix.


I haven't programmed for unix in a couple decades, but you might check out termifo and termcap libraries.

LOL! I know, it has not been the trend for a while but a lot of people have started switching to it because windows and Macs are quite expensive compared to something you can get for free!

Anyways, thanks for the reply, i'll look into them and will let you know.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.