Solved

gotoxy() in dev-c++

Posted on 2002-06-05
16
22,382 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 147
How to gracefully close the c++ 11 thread? 3 66
Arduino EDI - Programming language 3 62
Safe conversion? 4 17
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now