C++ FUNCTION TO SET CURSOR ON THE CONSOLE



C++ CODE TO SET CURSOR ON THE CONSOLE
This is a code having function of place cursor,which place the cursor on the console according to coordinates.Forexample,you want to print any thing at position 10,10 you will call function PlaceCursor(10,10) and than print it.


HAPPY CODING!



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

using namespace std;


//this is function for place cursor
void PlaceCursor(int x,int y)
{
    COORD c;
    c.X = x;
    c.Y = y;

    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(h,c);
}

int main()
{
    PlaceCursor(5,5);//this is position of cursor at console

    cout<<"HELLO WORLD"<<endl;//hello world will be  //printed at 5,5

    system("pause");
    return 0;
}




No comments:

Post a Comment