Solved

gotoxy() in dev-c++

Posted on 2002-06-05
16
22,902 Views
Last Modified: 2012-05-04
Using Dev-C++ 5 Beta 3:

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

int main()
{
  gotoxy(1,1); // Not important where
  cout << "Hello world.";
} // end main()
----

Returns the error "[Linker error] undefined reference to 'gotoxy'"

I've used gotoxy from conio.h in other compilers without any trouble. What's going on here?

I checked conio.h and it does have this single line: void gotoxy(int x, int y);

----

(Standard disclaimer: Note that I'm still a beginning programmer and my biggest obstacle has always been people assuming I know more than I do. Please don't answer like someone else did with something like "Try SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), (COORD) {x - 1, y - 1});" You'll only get a blank stare back. Also, telling me to get a new compiler, go buy a book or try some other library isn't a solution I will grant answer credit for. I can do BASIC without a hitch. Small bumps in the c++ road become insurmountable obstacles because people aren't willing to give simple answers that do exist. I don't mean to be rude but this is the only way I can get answers I can use from long-time programmers.)
0
Comment
Question by:Decimal
  • 5
  • 4
  • 3
  • +2
16 Comments
 
LVL 2

Accepted Solution

by:
LoungeLizard earned 300 total points
ID: 7058416
You are quite right. There is a prototype called gotoxy in conio.h, but there is no implementation for it in the standard G++ libraries. This is because conio.h it is NOT part of the ANSI C++ standard.

If you want to use it on a DOS/Windows platform, you have to include the libraries as well. Goto Project -> Project Options -> Load Object files and include conio.o

The reason why it works on other compilers is because they were written for DOS/Windows and had the libraries included by default. G++ is not written for a specific platform
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7058680
Hi Decimal,
Do you understand that the function gotoxy() is an obsolete function related to using the old DOS-prompt style character-only screens?  It is almost never used these days.  

In general, there are two types of programs:

1) If you just need to scroll some text onto a character-mode screen or for programs that require little or no user interaction, C++ programmers might choose to write a console-oriented program and use printf or cout for displaying text on the screen.

2) If you need to interact with the user or perform any sort of intricate screen manipulation, you will want to use a GUI interface -- windows, dialog boxes, mouse, the whole banana.  I'm sure you've hear of it.

=-=-=-=-=-=-=-=-=-=-=-=-=-
The gotoxy() function belongs in neither of these scenarios.  That is why you have found unexpected errors in attempting to use it -- no programmer on God's Green Earth has used it in the last 10 years at least.  

-- Dan
0
 
LVL 1

Expert Comment

by:Shivshankar
ID: 7058826
Dan,
>>no programmer on God's Green Earth has used it in the >>last 10 years at least
  I can't help but disagree in this aspect. DOS 6.22 was used for sometime even after Windows 95 was launched. So, there should be a subset of programmers working to produce some DOS based text-editors which definitely need console functions. Even in Windows NT, the support for DOS's "edit" is not withdrawn. All these arguments, I guess, counter your views.

Best Regards.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:jkr
ID: 7059060
Use 'SetConsoleCursorPosition()' instead...
0
 

Author Comment

by:Decimal
ID: 7059881
What library has SetConsoleCursorPosition?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7059896
kernel32.lib contains the reference to this function.

BTW, for a sample on how to use it, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/conchar_156b.asp ("Using the High-Level Input and Output Functions").
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7060025
From the initial question:
>>Please don't answer like someone else did with something
like "Try SetConsoleCursorPosition ...

lol
-- Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 7060032
Ooops, I missed that one. Nevertheless, it is the answer (except maybe a Win32 port of 'curses')
0
 

Author Comment

by:Decimal
ID: 7060232
Well, it was more the way it was put. I.E. Try SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), (COORD) {x - 1, y - 1});

Huh? :)
0
 

Author Comment

by:Decimal
ID: 7060238
SetConsoleCursorPosition is way too complicated. I'll have to find another alternative. :/ Why, oh WHY isn't there a simple, Standard, non-MS equivelant to the BASIC "Locate" statment?
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 7060349
Thanks for the points, but why did you give me a B ? Did I not 100% answer your question, which was "I've used gotoxy from conio.h in other compilers without any trouble. What's going on here?"
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7060424
>>Why, oh WHY isn't there a simple, Standard, non-MS equivelant to the BASIC "Locate" statment?

There is.  Why didn't you ask for that?  

Instead you asked about a linker error, giving us reams of information about what you didn't want.  When I offered detailed background, you did not respond.  When LoungeLizard answered your question and solved your problem as stated, you stuck him with a B.
0
 

Author Comment

by:Decimal
ID: 7060505
Er, is a B so terrible? It says "Good!". That's how I felt about it. Perhaps it did deserve an A, but isn't hindsight 20/20? Even if it was worth being bitter over, you're not the one who should feel that way.

As for your reply - your detailed "background", in fact your entire response is easily summed up as "Why would you want to do that? Don't do that!" Then you followed up with "There is (but I'm not happy with you so I'll keep the information to myself.)" I'm not interested in a flame war.

The question of how to use the "locate" equivalent in C++ was a one I asked before on Experts Exchange, and the answer came in the form of gotoxy().
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 7060648
I don't want to start a flamewar. I'm also not upset at not getting maximum points. I'm trying to find out why you thought my answer was incompelete. If you are not happy about an answer, then you should say so, and I'll try to explain/expand if possible.

BTW, my answer was NOT "Why would you want to do that? Don't do that!"

0
 

Author Comment

by:Decimal
ID: 7060724
Lounge: Look, if there is a way to correct the grade I'd be happy to do it. As for incompleteness, when I went to Dev-C++ and added conio.o to the Project Options -> General Tab -> Linker Options/Optional Libs or Object Files it didn't solve the problem, because it couldn't find "conio.o". And honestly, it wasn't something I gave a terrible lot of thought about at the moment when I gave the grade. I simply looked at the answers available and thought "Good!" was a decent description of your answer (Thanks, by the way) considering you had answered it adequately but I was still stuck. Had you mentioned another simpler/standard way to do it, you certainly would have gotten the A. But like I said, if there's a way to fix the grade I'm quite willing to do so anyhow.

My last reply was not directed towards you, but to DanRollins. It was he who gave the answer of:

"Do you understand that the function gotoxy() is an obsolete function related to using the old DOS-prompt style character-only screens? [...] 1) If you just need to scroll some text onto [...] 2) If you need to interact with the user or perform any sort of intricate screen manipulation, you will want to use a GUI interface [...]

Which is little different from "Why would you want to do that? Don't to that!"
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7060856
Whew.  Glad that's cleared up.

-- Dan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question