VB icon

A copy of PASCAL:s GOTOXY for C++ (UPDATED)

Email
Submitted on: 1/4/2015 6:46:00 AM
By: Martin Mikaelsson (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: Microsoft Visual C++
Views: 1904
 
     The same way like PASCALs GotoXY. It let you place the textcursor anywhere on the console_screen. UPDATE (2002-12-5) now shows how to use GotoXY in loops.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :A copy of PASCAL:s GOTOXY for C++ (UPDATED)
//**************************************
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
#include <winbase.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A copy of PASCAL:s GOTOXY for C++ (UPDATED)
// Description:The same way like PASCALs GotoXY. It let you place the textcursor anywhere on the console_screen.
UPDATE (2002-12-5) now shows how to use GotoXY
in loops.
// By: Martin Mikaelsson (from psc cd)
//**************************************

//***************************************************************
//
// GOTOXY.CPP
// 
// When I programmed in PASCAL for 2 years ago I find the command
// GotoXY; very useful in my programs.
// But in C++ "GotoXY; only existed on Borland C++!!!!!!!!
// So, my dad and I have made an own GotoXY and it takes two
// parameters.
//
// And by the way... I'm swedish.
//
// Snillet98
//
//***************************************************************
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
#include <winbase.h>
void GOTOXY ( WORD y, WORD x);
HANDLEhStdIn;
HANDLEhStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
int main()
{
	GOTOXY(2,2);	// Set textcursor to Y = 2 and X = 2
	cout << "Writing here now" << endl;
	GOTOXY(3,3);
	cout << "And now here" << endl;
	GOTOXY(4,4);
	cout << "What? Now I came here!" << endl;
	GOTOXY(5,5);
	cout << "Jump, jump, jump" << endl;
	printf("%s \n", "Press any key to continue");
	getch();
	GOTOXY(2,2);	// This string will overwrite the first string
	cout << "Ops! Now I owerwrite someting!" << endl;
	GOTOXY(6,0);
	printf("%s \n", "Press any key to continue");
	getch();
	system("CLS");
	for(int i=0;i<20;i++)
	{
		GOTOXY(i,i*2);
		printf("*");
	}
	
	return 0;
}
void GOTOXY ( WORD y, WORD x)	// This is GOTOXY function with two parameters
{
	hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	hStdIn = GetStdHandle(STD_INPUT_HANDLE);
	GetConsoleScreenBufferInfo( hStdOut, &csbiInfo );
	COORD coordScreen;
	coordScreen.X = x;
 	coordScreen.Y = y;
 
 	(void) SetConsoleCursorPosition(hStdOut, coordScreen);
}
// No much comments here but I think you understand the most of this code
// NOTE! This is my first code I upload here. So please, tell me how good it is.


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.