Which header file I need to include to use gotoxy() function?

前端 未结 7 2064
夕颜
夕颜 2021-01-07 04:06

This is the student-report-card-project, I got some problems when I shifted this code to the dev C++ from borland C. Now when I try to complile the program in dev C++, it gi

相关标签:
7条回答
  • 2021-01-07 04:07

    conio.h but it isn't standard. You need to check if your OS (console) can handle it.

    #include <conio.h>
    
    0 讨论(0)
  • 2021-01-07 04:09

    You could write it on your own:

    void gotoxy(int x, int y)
    {
        COORD c = { x, y };  
        SetConsoleCursorPosition(  GetStdHandle(STD_OUTPUT_HANDLE) , c);
    }
    
    0 讨论(0)
  • 2021-01-07 04:10

    You'll need to create it yourself. Include <windows.h>, then:

    void gotoxy(int x, int y)
    {
      static HANDLE h = NULL;  
      if(!h)
        h = GetStdHandle(STD_OUTPUT_HANDLE);
      COORD c = { x, y };  
      SetConsoleCursorPosition(h,c);
    }
    

    I shouldn't have to say it, but obviously this is not portable outside Windows, if even that far.

    0 讨论(0)
  • 2021-01-07 04:10

    <conio.h> is part of DOS Based Turbo C++ Compiler. Remember the Blue Screen Compiler.

    0 讨论(0)
  • 2021-01-07 04:15

    there is a small piece of code which works for me most of the time.....

    #include<iostream>
    #include<iomanip>  //for setw(); 
    
    using namespace std;
    
    gotoxy(int x, int y)
    {
      cout<<setw(x);  //horizontal
    
      for(;y>0;y--)   //vertical
        cout<<endl;
     }
    
    int main()
    {
      gotoxy(10,20);
      cout<<"ANYTHING";
      return(0);
    }
    
    0 讨论(0)
  • 2021-01-07 04:24

    add this header and function in your code:

    #include "windows.h"
    
    void gotoxy(int x, int y) 
    { 
        COORD coord;
        coord.X = x; 
        coord.Y = y;
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    0 讨论(0)
提交回复
热议问题