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)
[解决办法]
我的VC6.0可以运行啊 没报错啊
楼主把那个预编译器头文件#include "stdafx.h"
删掉 我删掉后可以运行 没报错
[解决办法]
看错误提示,是说getch()无法识别,换getchar()试试。
另外说一下,建议尽量不要用VC6.0了,虽然“经典”,但经典过头了,现在一些标准已经不支持了。
[解决办法]
getch(),kbhit()这两个函数未找到实现,
[解决办法]
这种老土的api还搞干吗,应该学习GUI设计了