我使用Visual Studio 2010和我想移动光标时,键盘上的用户按右键数组键:c + +移动光标在控制台
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
void gotoxy(int x, int y)
{
static HANDLE h = NULL;
if(!h)
h = GetStdHandle(STD_OUTPUT_HANDLE);
COORD c = { x, y };
SetConsoleCursorPosition(h,c);
}
int main()
{
int Keys;
int poz_x = 1;
int poz_y = 1;
gotoxy(poz_x,poz_y);
while(true)
{
fflush(stdin);
Keys = getch();
if (Keys == 77)
gotoxy(poz_x+1,poz_y);
}
cin.get();
return 0;
}
它的工作,但只有一次 - 第二,第三等按下不工作。
'fflush(stdin);' - 不这样做。我不想忍受由于代码中的一行而自发燃烧的可能性。 – chris