You are here:

C++/input output manipulation


This question is about how i can set my blinking cursor at a place that i want? i have been using the 'gotoxy(int,int)' for turbo C language to calculate where it will start to input, or where the words or character printed on the screen,...the real question is there any build in function such as 'gotoxy(int,int)' for turbo C in microsoft visual C++...or how can i build one and implement one into microsoft visual C++...

The C and C++ language standards have _no_ support for such functions - so the Turbo C function you mention is something invented by Borland.

From what you say you are writing MS Windows console programs or - in the case of Turbo C - possibly MS DOS.

I shall assume you are using a 32-bit (Win32) operating system as you have not stated what operating system you are using. Visual C++ implies MS Windows - unless you are using a really ancient 16-bit version.

The reason the operating system is important is that it determines what system API (Application Programming Interface) functions or libraries are likely to be available - and it is an operating system dependent function you need to use in this case.

As an aside, there is a UN*X (and Linux) library called curses (or ncurses) that performs terminal-based operations. It originally was intended for use with real terminals which tended to required various control code sequences to perform the sort of operations you are after. Today of course many people will just use an xterm session under the X window system on these platforms. No doubt there are MS Windows ports of this library if you wanted one and you should be able to locate documentation fairly easily from a search engine query.

However, if you are not concerned about doing it the UN*X way then you can use the Win32 console API functions directly.

The function you require is SetConsoleCursorPosition, however before you use this function you have to obtain a handle to the screen buffer of the console you are using - for a simple program which is running in a pre-created console window you can obtain such a handle using the GetStdHandle function and passing it STD_OUTPUT_HANDLE. Note you should (as usual with MS Windows API programming) include windows.h.

I could explain these functions in detail, however MS freely provide this information in the MSDN library - a version of which should be included on CD with MS Visual C++ (version 6 or later). Alternatively you can find the information at - try starting here:

(note the preceding URL is long and so is most likely wrapped over several lines). Or start at and select:

Windows Development / Windows Base Services / DLLs, Processes and Threads / DLLs, Processes and Threads / Character Mode Applications

from the tree navigation control on the left side of the page. I found that MS have changed the system since I last used it so you can skip some of the intervening steps by using links on pages that appear on the right.

Here is a sample program:

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

       int main()
         HANDLE hConsole( GetStdHandle(STD_OUTPUT_HANDLE) );

         COORD pos;
         pos.X = 10;
         pos.Y = 10;

         SetConsoleCursorPosition( hConsole, pos );

         std::cout << "Hello\n";

         return 0;

On a final note: these are not the only things you can do with consoles. You might like to look into some of the other console APIs such as GetConsoleScreenBufferInfo, FillConsoleOutputCharacter, SetConsoleTextAttribute (which were just the functions that I chose to use in the full version of the program from which the sample program above was a part).  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2016 All rights reserved.