Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Locate function in C++

Tue Dec 09, 2003 4:27 am

Hi, Just wondering

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++?
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
madgun
Gerbil Team Leader
Posts: 267
Joined: Tue Aug 05, 2003 11:16 am

Tue Dec 09, 2003 5:46 am

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.
There's no fate but what we make for ourselves.
 
Hawkwing74
His Holy Gerbilness
Posts: 13961
Joined: Wed Aug 20, 2003 5:51 pm
Location: Streamwood, IL

Re: Locate function in C++

Tue Dec 09, 2003 12:26 pm

fc34 wrote:
Hi, Just wondering

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++?

Are you in school using QB? I can't think of any other use for QB except to learn programming :P
 
madgun
Gerbil Team Leader
Posts: 267
Joined: Tue Aug 05, 2003 11:16 am

Tue Dec 09, 2003 12:34 pm

:oops:
Last edited by madgun on Tue Dec 09, 2003 12:48 pm, edited 1 time in total.
There's no fate but what we make for ourselves.
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Tue Dec 09, 2003 12:43 pm

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.

On what platform, and using what library? This is not a standard part of C++.

fc34, the answer to your question is... it is platform-specific.
Nostalgia isn't what it used to be.
 
madgun
Gerbil Team Leader
Posts: 267
Joined: Tue Aug 05, 2003 11:16 am

Tue Dec 09, 2003 12:47 pm

you can do that on turbo c++
and there is a specific cammand on vc++ regarding goto
There's no fate but what we make for ourselves.
 
madgun
Gerbil Team Leader
Posts: 267
Joined: Tue Aug 05, 2003 11:16 am

Tue Dec 09, 2003 1:03 pm

try doing this in bc/tc:



#include <conio.h>
#include <iostream.h>



int main()
{
clrscr();
gotoxy(10, 10);
cout<<"madgun mania!"<<endl;
getch();
return 0;
}


in vc++ there is no gotoxy function therefore u cant use that in vc++.

however go to is a completely different thing whereby u point to a label eg:



#include<iostream.h>

void main()
{


goto label;
label:
cout<<"madgun mania!";


}
Last edited by madgun on Tue Dec 09, 2003 1:05 pm, edited 1 time in total.
There's no fate but what we make for ourselves.
 
moog
Gerbil Elite
Posts: 868
Joined: Wed Jun 11, 2003 9:10 am

Tue Dec 09, 2003 1:04 pm

conio.h has gotoxy

But if you're using windows and vis c++, look here: http://spike.scu.edu.au/~jmaltby/c.html

Edit: Here it is from the site.

#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
}
 
Last edited by moog on Tue Dec 09, 2003 1:17 pm, edited 1 time in total.
 
madgun
Gerbil Team Leader
Posts: 267
Joined: Tue Aug 05, 2003 11:16 am

Tue Dec 09, 2003 1:11 pm

yeah but setxy calculates the graphical pixels in a different way.
it calculates it like 80 by 60


(in my above eg iostream.h is missing)
There's no fate but what we make for ourselves.
 
mac_h8r1
Minister of Gerbil Affairs
Posts: 2974
Joined: Tue Sep 24, 2002 6:57 pm
Location: Somewhere in the Cloud
Contact:

Tue Dec 09, 2003 1:13 pm

IIRC, gotoxy is a member funciton of the conio library.

you could write your own function, if you wanted to.

void gotoxy(int x,int y){
for(int goY=0;goY<y;goY++) cout<<endl;
for(int goX=0;goX<x;goY++) cout<<' ';
}
mac_h8r1.postCount++;
Chaos reigns within. Reflect, repent, and reboot. Order shall return.
Slivovitz owns you.
 
madgun
Gerbil Team Leader
Posts: 267
Joined: Tue Aug 05, 2003 11:16 am

Tue Dec 09, 2003 1:24 pm

in windows unlike bc we have to predefine the gotoxy.
By the way conio.h gives an error of an undeclared indentifier in vc++
There's no fate but what we make for ourselves.
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Tue Dec 09, 2003 1:33 pm

Looks like moog beat me to it...

Yes, the SetConsoleCursorPosition API call should work for all versions of Windows since Win95, and with any C++ compiler.

On UNIX/Linux, you can send ANSI terminal escape sequences directly to standard output, and they will be interpreted by the shell window... e.g.:
printf("\x01b[%d;%dH", Y, X);

will position the cursor to row Y, column X in a UNIX shell window.
Nostalgia isn't what it used to be.
 
Buub
Maximum Gerbil
Posts: 4969
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA
Contact:

Wed Dec 10, 2003 12:12 am

C++ is a language. It is used to compile source code into programs. It can do that on almost any platform in the world. It has a standard library so you can do useful things with those programs.

Now, can you tell me where gotoxy(50, 30) would go on an embedded heart monitoring machine? Maybe on a robot building cars?

The answer is: No. C++ doesn't have any idea what you're sending output to. To C++, it's all either a file or is accessed through some add-on API.

Which is what you're looking for (and which some of these people mentioned indirectly). You're looking for a library specific to a PC that knows how to manipulate the video screen. Microsoft and Borland, two mentioned above, include such libraries with their systems. But that is not "C++"; it's the add-on run-time libraries from MS and/or Borland.

I'm not trying to be an ass, really. :-) The differences are subtle but very important. "C++" is not printing characters on your screen; someone's PC-specific library is doing so. One reason why this is important is illustrated above: Microsoft and Borland have different ways to do the same thing. So even on a PC with a PC C++ compiler, it still depends on whose compiler libraries you're using. It's also one of the reasons C++ has stuck around so long; it really is platform independent and can be extended to just about anything with a CPU in it.

Anyway, yes, in MSVC (or whatever) there are functions that will do that, and the guys above have given some good examples already.
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Wed Dec 10, 2003 12:33 am

Yes, when I said:
the SetConsoleCursorPosition API call should work for all versions of Windows since Win95, and with any C++ compiler

what I meant was any C++ compiler that supports the standard Windows SDK (since SetConsoleCursorPosition is in fact a Win32 system call)... not any C++ compiler on any arbitrary platform. The gotoxy function is apparently Borland-specific; but provided that the Borland compiler supports the standard Windows SDK headers, SetConsoleCursorPosition should work with either VC++ or Borland.

Obviously SetConsoleCursorPosition will not work on non-Windows platforms; hence my alternative example for accomplishing the same thing for an ANSI terminal window under UNIX.
Nostalgia isn't what it used to be.
 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Re: Locate function in C++

Wed Dec 10, 2003 6:08 am

Hawkwing74 wrote:
fc34 wrote:
Hi, Just wondering

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++?

Are you in school using QB? I can't think of any other use for QB except to learn programming :P


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 :D
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
Hawkwing74
His Holy Gerbilness
Posts: 13961
Joined: Wed Aug 20, 2003 5:51 pm
Location: Streamwood, IL

Re: Locate function in C++

Wed Dec 10, 2003 10:38 am

fc34 wrote:
Hawkwing74 wrote:
Are you in school using QB? I can't think of any other use for QB except to learn programming :P


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 :D

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
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Re: Locate function in C++

Thu Dec 11, 2003 6:22 am

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 :P


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 :D

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.


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...
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
Hawkwing74
His Holy Gerbilness
Posts: 13961
Joined: Wed Aug 20, 2003 5:51 pm
Location: Streamwood, IL

Re: Locate function in C++

Thu Dec 11, 2003 9:34 am

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.
 
Buub
Maximum Gerbil
Posts: 4969
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA
Contact:

Fri Dec 12, 2003 12:18 am

VB is for MIS guys who don't want to learn how to program.
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Fri Dec 12, 2003 1:44 am

Buub wrote:
VB is for MIS guys who don't want to learn how to program.

:D

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!)
Nostalgia isn't what it used to be.
 
Craig P.
Gerbil Team Leader
Posts: 285
Joined: Tue Dec 31, 2002 3:12 am
Location: South Bend, IN

Mon Dec 15, 2003 12:09 am

VB is very capable when you've worked with it enough to know how to use it. Even though I'm very good with C++, I'm still quite fond of VB and use it when I don't plan on going beyond its capabilities.
 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Re: Locate function in C++

Sat Dec 20, 2003 1:01 am

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.


Well, same here...thats y i am asking the question about C++, having been taught how to program in QB.
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
RNBW
Gerbil In Training
Posts: 1
Joined: Sun Sep 17, 2017 2:44 pm

Re: Locate function in C++

Sun Sep 17, 2017 2:54 pm

I know this is in reply to an old thread, but I am learning C++ and wanted an equivalent to the BASIC Locate x,y.

I tried (moog » Tue Dec 09, 2003 6:04 pm)'s solution and with a bit of modification got it to work on Windows using GCC. The code follows:
//================================
// 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;
}


There may be a better way. If so could someone advise.
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Locate function in C++

Sun Sep 17, 2017 3:19 pm

Seems reasonable to me. The only caveat I've got is that it won't work on non-Windows OSes.
Nostalgia isn't what it used to be.
 
DancinJack
Maximum Gerbil
Posts: 4494
Joined: Sat Nov 25, 2006 3:21 pm
Location: Kansas

Re: Locate function in C++

Sun Sep 17, 2017 4:58 pm

Nearly a 14 year necro. Seems like some kind of record.
i7 6700K - Z170 - 16GiB DDR4 - GTX 1080 - 512GB SSD - 256GB SSD - 500GB SSD - 3TB HDD- 27" IPS G-sync - Win10 Pro x64 - Ubuntu/Mint x64 :: 2015 13" rMBP Sierra :: Canon EOS 80D/Sony RX100
 
ludi
Lord High Gerbil
Posts: 8646
Joined: Fri Jun 21, 2002 10:47 pm
Location: Sunny Colorado front range

Re: Locate function in C++

Sun Sep 17, 2017 5:52 pm

DancinJack wrote:
Nearly a 14 year necro. Seems like some kind of record.

But with a valid question! Usually these get dug up by a spam bot.
Abacus Model 2.5 | Quad-Row FX with 256 Cherry Red Slider Beads | Applewood Frame | Water Cooling by Brita Filtration
 
derFunkenstein
Gerbil God
Posts: 25427
Joined: Fri Feb 21, 2003 9:13 pm
Location: Comin' to you directly from the Mothership

Re:

Sun Sep 17, 2017 8:03 pm

just brew it! wrote:
Buub wrote:
VB is for MIS guys who don't want to learn how to program.

:D

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!)

Since this thread has been resurrected already and I won't feel bad about a necro getting off-topic, I have to say.... I took a VB class fall 2016 and the final "project" was a point-of-sale system mock-up that needed six Windows forms built with the Visual Studio form designer. It was torture. I don't want to have to go through it again, except that my C# class this semester is basically "VB but with a different syntax".

There are so many other ways to use both of these languages. The problem with Visual Basic (or C# for that matter) is the visual part. I had expected this course to be more advanced since VB was a prerequisite, so I fooled around this summer with Xamarin Forms, which uses XAML to build the interface and C# under the hood. Silverlight was the first (that I know of) to go this route, but it's also used for Windows Universal apps. It's a way more interesting way to do things than clicking and dragging in the forms designer.

So I don't think it's the language that's the problem (although it might be suboptimal). It's the way it's taught and the way it was used by so many "MIS guys who don't want to learn how to program", as Buub said so long ago. Take that visual toolbox away and it's pretty great and extremely flexible, as long as you're sticking to WIndows (though that's changing a bit, too).
I do not understand what I do. For what I want to do I do not do, but what I hate I do.
Twittering away the day at @TVsBen
 
Pancake
Gerbil First Class
Posts: 161
Joined: Mon Sep 19, 2011 2:04 am

Re:

Sun Sep 17, 2017 9:30 pm

just brew it! wrote:
Buub wrote:
VB is for MIS guys who don't want to learn how to program.

:D

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!)


Visual Basic was the equivalent of web development in the '90s. Every monkey was doing it. The language was a complete **** totally unsuited for anything more than a few hundred lines but somehow it became THE main application development language. Unfortunately, the vast majority of developers are of extremely low quality so somehow that cancer of a development environment managed to spread. These days, the similarly garbage HTML 5 has taken over for much the same reasons and with much the same problems. Same low quality vermin promoting it. The triumph of mediocrity.
 
morphine
TR Staff
Posts: 11600
Joined: Fri Dec 27, 2002 8:51 pm
Location: Portugal (that's next to Spain)

Re: Locate function in C++

Sun Sep 17, 2017 11:00 pm

What's funny is, if the ease of use of VB actually had a good programming language behind it, it could have been in use still today.
There is a fixed amount of intelligence on the planet, and the population keeps growing :(
 
Pancake
Gerbil First Class
Posts: 161
Joined: Mon Sep 19, 2011 2:04 am

Re: Locate function in C++

Mon Sep 18, 2017 1:26 am

Probably what I most enjoyed about VB was making confident predictions which projects based on it would fail. Prototypes could be put together very quickly which would impress clients but with the choice of VB they had all the engineering integrity of a bridge built out of cheesy puffs. Fellow developers would get very upset as this young programmer making confident predictions of their failure. One particular project I was handed to fix was from a couple of guys while working at a large unnamed GIS company. They had been working on this hideous melange of VB, random ActiveX components - the whole Microsoft stack. Oh, that's right, VB programmers would also be MS devotees. Performance was terrible and didn't scale. There wasn't anything resembling a system architecture or even design rules. It gave me immense pleasure to tell the project manager I had to throw it all in the bin and start again in a language that you could actually do proper engineering in - Java. And sure enough, I succeeded where they failed.

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On