读书人

请教大家这个gotoxy函数没有用

发布时间: 2012-05-07 12:40:40 作者: rapoo

请问大家这个gotoxy函数没有用?
程序如下:

C/C++ code
#include <stdio.h>#include <stdlib.h>#include <windows.h>void gotoxy(int x,int y){    COORD C;    C.X = x;    C.Y = y;    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),C);}int main(){    printf("Hello world!\n");    gotoxy(300,400);    printf("Hello world!\n");    system("pause");    return 0;}


[解决办法]
int main()
{
printf("Hello world!\n");

gotoxy(10,20);
printf("Hello world!\n");

system("pause");
return 0;
}
MSDN:The coordinates must be within the boundaries of the console screen buffer.
按照原先的300,400,检测SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),C)返回值为0;

读书人网 >C语言

热点推荐