Windows.h: COORD function error

This is a discussion on Windows.h: COORD function error within the C++ Programming forums, part of the General Programming Boards category; I have use a function of <windows.h> library. And I have met error with MS Visual Studio 2010, but when ...

  1. #1
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115

    Question Windows.h: COORD function error

    I have use a function of <windows.h> library. And I have met error with MS Visual Studio 2010, but when I compiled on Dev-C++, No problem. Here my code:
    Code:
    void gotoXY(int x, int y)
    {
    	COORD coor;
    	coor.X=x;
    	coor.Y=y;
    	int a =coor.X;
    	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coor);
    }
    void clearLine(int line)
    {
    	COORD coor;
    	int x=coor.X;
    	int y=coor.Y;   //Error in this line: VS 2010 . but no problem in Dev-C++
    	gotoXY(0,line);
    	for(int i=0;i<50;i++) std::cout<<" ";
    	gotoXY(x,y);	//back to the past cursor
    }
    int main ()
    {
    	 gotoXY(3,4);
    	 clearLine(0);
    	 getch();
       return 0;
    
    }
    when I compile, VS tak error:
    the vaialbe 'coor' is being used without being initalized
    who know this problem, tell to me,please.
    thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,560
    In the following snippet:
    Code:
    void clearLine(int line)
    {
        COORD coor;
        int x=coor.X;
        int y=coor.Y;   //Error in this line: VS 2010 . but no problem in Dev-C++
        gotoXY(0,line);
        for(int i=0;i<50;i++) std::cout<<" ";
        gotoXY(x,y);    //back to the past cursor
    }
    }
    Where does the value coor.X and coor.Y come from? Before you can use these values in a equation they must be assigned a value.

    Also if you turn on the warnings with Dev-C++ it would also produce some warnings.

    Jim

  3. #3
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115

    Question

    Oh, thanks very much. May I have understand. if I don't thinking wrong, coor.X and coor.Y are just parameter of struct COORD. (but before that, I think coor.X and coor.Y is the present cursor) so I get the present cursor and save it.
    So, how can I take the current cursor, can you teach me ?
    thanks

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,266
    Search the web for how to use the GetConsoleScreenBufferInfo function for that purpose.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-27-2008, 06:41 PM
  2. Question about COORD
    By RealityFusion in forum C++ Programming
    Replies: 1
    Last Post: 09-30-2005, 06:02 PM
  3. coord...
    By b00l34n in forum C++ Programming
    Replies: 5
    Last Post: 04-10-2004, 03:40 PM
  4. POINT and COORD
    By Extol in forum Windows Programming
    Replies: 0
    Last Post: 04-17-2003, 04:04 PM
  5. Coord system
    By RubenJ in forum Windows Programming
    Replies: 4
    Last Post: 10-25-2001, 06:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21