-4

I included cstdlib, stdlib.h, stdio.h, conio.h, iostream, and then I typed using namespace std...(bla bla bla bla), and gotoxy()...But then the red curly underline and build(loading...) and... "build failed"... Then okay, I tried many times and nothing.Can anybody (please!!) tell me what`s wrong with the code? Here it is:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <conio.h>
using namespace std;
int main()
{
    gotoxy(20, 30);
}

I consider that THIS function is not supposed to be declared before use

By the way thank you in advance cause I`m desperate

Mr.Stark135
  • 1
  • 1
  • 6
  • 2
    I believe that function is only provided by turbo C. Edit : Please do not migrate to turbo C to get access to this feature. It's not worth it. – François Andrieux Apr 11 '19 at 15:11
  • 2
    `gotoxy(int x, int y);` you are not calling a function. – drescherjm Apr 11 '19 at 15:11
  • 1
    Your compiler can: it outputs error messages that are at least a little more informative than "Build failed". Your issue seems to be that you try to call `gotoxy` but are repeating its parameters' type, and that's not how C++ works. – Quentin Apr 11 '19 at 15:11
  • What are `x` and `y` and what are the `int`s supposed to do? Please find a tutorial on using/calling functions. – Yunnosch Apr 11 '19 at 15:11
  • What do you intend to achieve by this line? `gotoxy(int x, int y);` Declare a function? Call a function? For what purpose? – Yunnosch Apr 11 '19 at 15:13
  • Thank you Yunnosch for answers – Mr.Stark135 Apr 11 '19 at 15:20
  • But drescherjm I am calling a function – Mr.Stark135 Apr 11 '19 at 15:23
  • `gotoxy` is (IIRC) something Turbo C / Turbo C++ provided some 20-30 years ago. If I remember correctly, then *please* forget about it. Those ancient, pre-standard products should *not* be used in 2019. – Jesper Juhl Apr 11 '19 at 15:50
  • Consider using a [curses library](https://en.m.wikipedia.org/wiki/Curses_(programming_library)), like [ncurses](https://en.m.wikipedia.org/wiki/Ncurses), for a portable solution. – Jesper Juhl Apr 11 '19 at 15:58
  • 2
    ***But drescherjm I am calling a function*** Not correctly. With the `int` before the `x` and `y` you are almost declaring a function. If you had a return type it would be a valid declaration. – drescherjm Apr 11 '19 at 16:19
  • 1
    I recommend a change of reference materials. [Here is a curated list of widely respected books on C++.](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – user4581301 Apr 11 '19 at 16:51
  • Thank you Jesper for complete explanation about that.It seems that I was looking for wrong thing. Thanks for all of you guys and loss of your time. – Mr.Stark135 Apr 15 '19 at 19:16
  • About curses and ncurses. I did not understand the point with those libaries despite I read a few sites about that. But do not answer in comment cause I chose not to try to understand or even use that – Mr.Stark135 Apr 23 '19 at 08:41
  • bye bye now I need to go – Mr.Stark135 Apr 23 '19 at 08:42
  • And once more I appreciate everything you have done for me – Mr.Stark135 Apr 23 '19 at 08:42
  • acctually folks I am just putting these comments to earn a badge – Mr.Stark135 Apr 23 '19 at 08:55
  • bla bla bla bla bla bla – Mr.Stark135 Apr 23 '19 at 08:56
  • Just do not hate me because of this I just want to learn something everyone I behaving like a GOD in front of me (the poor Idiot). OK those good guys like ``François Andrieux`` ``drescherjm`` ``Jesper Juhl`` ``Yunnosch`` ``Quentin`` are not counted – Mr.Stark135 Apr 23 '19 at 08:58

1 Answers1

2

For VC++ you can use SetConsoleCursorPosition() to define you own function, since gotoxy() function is not available in the standard libraries:

#include <windows.h>    
void gotoxy(int x, int y)
{
    COORD coordinate;
    coordinate.X = x;
    coordinate.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordinate);
}
seccpur
  • 4,996
  • 2
  • 13
  • 21