In QB, we can use the
locate x,y
function to print text to a certain location on the screen.
Is there such a command in C++?
Personal computing discussed
Moderators: renee, SecretSquirrel, just brew it!
locate x,y
fc34 wrote:Hi, Just wondering
In QB, we can use theCode: Select alllocate x,y
function to print text to a certain location on the screen.
Is there such a command in C++?
madgun wrote:yes there is a goto command
you can use gotoxy
give the pixel coordinates of x and y
do any thing on the screen at that location.
#include <iostream.h>
#include <windows.h>
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
void main()
{
gotoxy(20,10);
cout << "WOW!" << endl; // need to flush buffer with endl
gotoxy(10,7);
cout << "WOW!" << endl;
gotoxy(0,23); // position the final Visual C++ prompt
}
void gotoxy(int x,int y){
for(int goY=0;goY<y;goY++) cout<<endl;
for(int goX=0;goX<x;goY++) cout<<' ';
}
printf("\x01b[%d;%dH", Y, X);
the SetConsoleCursorPosition API call should work for all versions of Windows since Win95, and with any C++ compiler
Hawkwing74 wrote:fc34 wrote:Hi, Just wondering
In QB, we can use theCode: Select alllocate x,y
function to print text to a certain location on the screen.
Is there such a command in C++?
Are you in school using QB? I can't think of any other use for QB except to learn programming
fc34 wrote:Hawkwing74 wrote:Are you in school using QB? I can't think of any other use for QB except to learn programming
Hehe. For some reason, the IB (International Bacculaurate) requires that a BASIC language be taught.
The choices being VB and QB.
Since I didnt like VB, I chose QB
Hawkwing74 wrote:fc34 wrote:Hawkwing74 wrote:Are you in school using QB? I can't think of any other use for QB except to learn programming
Hehe. For some reason, the IB (International Bacculaurate) requires that a BASIC language be taught.
The choices being VB and QB.
Since I didnt like VB, I chose QB
Hmmm, VB is much better but to each his own. Yeah, I had to take QB as well and I really enjoyed it. It was the first programming class I ever had and I think it's decent for learning structure types and logic.
fc34 wrote:Personally I wouldnt touch VB or even QB. I would go for either C++, perl or python etc etc.
However, on a side note though, I should add that every person likes a different language. To each his own...
Buub wrote:VB is for MIS guys who don't want to learn how to program.
Hawkwing74 wrote:fc34 wrote:Personally I wouldnt touch VB or even QB. I would go for either C++, perl or python etc etc.
However, on a side note though, I should add that every person likes a different language. To each his own...
They didn't give us those kind of options... you could take C++ after QB.
//================================
// This provides a C++ equivalent
// to BASIC's Locate x,y
//================================
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
int main(int argc, char** argv)
{
gotoxy(20,10);
cout << "WOW!" << endl;
gotoxy(20,12);
cout << "Locates cursor in C++" << endl;
gotoxy(0,0); // Position the final Visual C++ prompt
return 0;
}
DancinJack wrote:Nearly a 14 year necro. Seems like some kind of record.
just brew it! wrote:Buub wrote:VB is for MIS guys who don't want to learn how to program.
VB isn't that bad... but I sure wouldn't want to try implementing a large, complex system with it!
(I'm a C/C++ guy from way back... lately I've been forced to learn Transact-SQL, which actually seems rather BASIC-like to me... yuck!)
just brew it! wrote:Buub wrote:VB is for MIS guys who don't want to learn how to program.
VB isn't that bad... but I sure wouldn't want to try implementing a large, complex system with it!
(I'm a C/C++ guy from way back... lately I've been forced to learn Transact-SQL, which actually seems rather BASIC-like to me... yuck!)