主题:VC6.0++里用不了 kbhit函数,请问怎么解决?
在VC6.0++里运行一个网上下载的代码,总会出现以下错误,求高手帮忙.(本人是菜鸟级别)
原码:
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <stdio.h>
#include "windows.h"
using namespace std;
void main()
{
char ch;
while (1)
{
if(kbhit())
{
ch = getch();
switch(ch)
{
case 'w':
cout << "向上运动!! " << endl;
break;
case 'a':
cout << "向左运动!! " << endl;
break;
case 'd':
cout << "向右运动!! " << endl;
break;
case 's':
cout << "向下运动!! " << endl;
break;
default:
break;
}
}
else
{
Sleep(2000);
cout << "自己运动!! " << endl;// 不按键!
}
}
system("pause");
}
编译结果:
--------------------Configuration: KbhitTest - Win32 Debug--------------------
Compiling...
KbhitTest.cpp
d:\program files\microsoft visual studio\vc98\include\conio.h(39) : warning C4229: anachronism used : modifiers on data are ignored
Linking...
KbhitTest.obj : error LNK2001: unresolved external symbol "int __cdecl getch(void)" (?getch@@YAHXZ)
KbhitTest.obj : error LNK2001: unresolved external symbol "int __cdecl kbhit(void)" (?kbhit@@YAHXZ)
Debug/KbhitTest.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
KbhitTest.exe - 3 error(s), 1 warning(s)
原码:
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <stdio.h>
#include "windows.h"
using namespace std;
void main()
{
char ch;
while (1)
{
if(kbhit())
{
ch = getch();
switch(ch)
{
case 'w':
cout << "向上运动!! " << endl;
break;
case 'a':
cout << "向左运动!! " << endl;
break;
case 'd':
cout << "向右运动!! " << endl;
break;
case 's':
cout << "向下运动!! " << endl;
break;
default:
break;
}
}
else
{
Sleep(2000);
cout << "自己运动!! " << endl;// 不按键!
}
}
system("pause");
}
编译结果:
--------------------Configuration: KbhitTest - Win32 Debug--------------------
Compiling...
KbhitTest.cpp
d:\program files\microsoft visual studio\vc98\include\conio.h(39) : warning C4229: anachronism used : modifiers on data are ignored
Linking...
KbhitTest.obj : error LNK2001: unresolved external symbol "int __cdecl getch(void)" (?getch@@YAHXZ)
KbhitTest.obj : error LNK2001: unresolved external symbol "int __cdecl kbhit(void)" (?kbhit@@YAHXZ)
Debug/KbhitTest.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
KbhitTest.exe - 3 error(s), 1 warning(s)