Search code examples
c++consoletextcolorcursor-position

How to use gotoxy() and textcolor() in C++


I'm using Codeblocks to coding my things using C++.

I remember that in C i can use gotoxy() features and textcolor(), but in C++ that library doesn't work.

Any idea?...

How can i use those functions in C++?.


Solution

  • gotoxy() and textcolor() are system dependent functions. They are not part of the standard and not portable.

    Two possibilities:

    1. with the same development environment you can get them to work in C and not in C++. In this case, its certainly conio2.h which doesn't provide for extern "C" for the C functions. The linker will not find them for this reason.

    2. with your new development environment these functons are not provided:

      • If you're under windows, you can have a look at this SO question to see how to create your own.
      • If you're under Linux, you'd better have a look at the curses/ncurses library. Or use it to emulate gotoxy() as explained here.