• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 24197
  • Last Modified:

gotoxy() in dev-c++

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
Decimal
Asked:
Decimal
  • 5
  • 4
  • 3
  • +2
1 Solution
 
LoungeLizardCommented:
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
 
DanRollinsCommented:
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
 
ShivshankarCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jkrCommented:
Use 'SetConsoleCursorPosition()' instead...
0
 
DecimalAuthor Commented:
What library has SetConsoleCursorPosition?
0
 
jkrCommented:
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
 
DanRollinsCommented:
From the initial question:
>>Please don't answer like someone else did with something
like "Try SetConsoleCursorPosition ...

lol
-- Dan
0
 
jkrCommented:
Ooops, I missed that one. Nevertheless, it is the answer (except maybe a Win32 port of 'curses')
0
 
DecimalAuthor Commented:
Well, it was more the way it was put. I.E. Try SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), (COORD) {x - 1, y - 1});

Huh? :)
0
 
DecimalAuthor Commented:
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
 
LoungeLizardCommented:
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
 
DanRollinsCommented:
>>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
 
DecimalAuthor Commented:
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
 
LoungeLizardCommented:
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
 
DecimalAuthor Commented:
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
 
DanRollinsCommented:
Whew.  Glad that's cleared up.

-- Dan
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now