为什么提示这样的错误

wbaxx 2013-09-01 10:22:38
#include <stdio.h>
#include <dos.h>

void main()
{
unsigned int freq; /* 指定的频率 */

do {
printf("Enter frequency: "); /* 显示键入频率的提示信息 */
scanf("%d",&freq); /* 接受键入的频率 */
if ( freq) { /* 频率不应为0 */
sound(freq); /* 开始发指定频率的声音 */
delay(1000); /* 延时一秒钟 */
nosound(); /* 关闭声音 */
}
} while ( freq ); /* 如指定的频率为0,则结束 */
}

F:\C++\sound\sound.cpp(12) : error C2065: 'sound' : undeclared identifier
F:\C++\sound\sound.cpp(13) : error C2065: 'delay' : undeclared identifier
F:\C++\sound\sound.cpp(14) : error C2065: 'nosound' : undeclared identifier
...全文
186 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
图灵狗 2013-09-04
  • 打赏
  • 举报
回复
用VirtualBox安装DOS6.22虚拟机,在DOS下安装Turbo C2.0,才能编译和运行你的程序。
引用 楼主 wbaxx 的回复:
#include <stdio.h> #include <dos.h> void main() { unsigned int freq; /* 指定的频率 */ do { printf("Enter frequency: "); /* 显示键入频率的提示信息 */ scanf("%d",&freq); /* 接受键入的频率 */ if ( freq) { /* 频率不应为0 */ sound(freq); /* 开始发指定频率的声音 */ delay(1000); /* 延时一秒钟 */ nosound(); /* 关闭声音 */ } } while ( freq ); /* 如指定的频率为0,则结束 */ } F:\C++\sound\sound.cpp(12) : error C2065: 'sound' : undeclared identifier F:\C++\sound\sound.cpp(13) : error C2065: 'delay' : undeclared identifier F:\C++\sound\sound.cpp(14) : error C2065: 'nosound' : undeclared identifier
hxm 2013-09-04
  • 打赏
  • 举报
回复
我觉得,如果你要用这个函数的话,你要明白两件事1.函数所包含的头文件;2.头文件所包含的函数。 具体点来说,你知道这三个函数都是在doc.h类库里,第一件事算完成了,第二件事就是你要查头文件里的函数的使用方法。
赵4老师 2013-09-03
  • 打赏
  • 举报
回复
dos.h顾名思义就是在dos下才灵啊。
wbaxx 2013-09-03
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
sound改为Beep delay改为Sleep
我把 sound(freq); delay(1000); nosound(); 这三句换成了一个Beep(freq,1000);然后加上Beep的头文件就可以了。不知道为什么sound()和delay()不行啊?它们不是包含在dos.h 中吗?
alex_my 2013-09-03
  • 打赏
  • 举报
回复
赵老师真是什么都通啊,膜拜下。
wbaxx 2013-09-03
  • 打赏
  • 举报
回复
引用 10 楼 zhao4zhong1 的回复:
dos.h顾名思义就是在dos下才灵啊。
dos.h应该是包含了一些dos调用函数吧,怎么是dos下才行呢
Qyee16 2013-09-02
  • 打赏
  • 举报
回复
估计你要用古老的编译器 TC了。。。
赵4老师 2013-09-02
  • 打赏
  • 举报
回复
sound改为Beep delay改为Sleep
max_min_ 2013-09-02
  • 打赏
  • 举报
回复

//这个几个函数那个(xxx)头文件提供给你的,包含进来
#include "xxx.h"
  sound(freq);              /*  开始发指定频率的声音  */
  delay(1000);              /*  延时一秒钟  */
  nosound();                /*  关闭声音  */
赵4老师 2013-09-02
  • 打赏
  • 举报
回复
换Beep! Beep The Beep function generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes. BOOL Beep( DWORD dwFreq, // sound frequency, in hertz DWORD dwDuration // sound duration, in milliseconds ); Parameters dwFreq Windows NT: Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF). dwDuration Windows NT: Specifies the duration, in milliseconds, of the sound. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks Windows 95: The Beep function ignores the dwFreq and dwDuration parameters. On computers with a sound card, the function plays the default sound event. On computers without a sound card, the function plays the standard system beep. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. See Also Errors Overview, Error Functions, MessageBeep
自信男孩 2013-09-02
  • 打赏
  • 举报
回复
是不是缺少库呢?需要你找到库,并连接进来。
羽飞 2013-09-01
  • 打赏
  • 举报
回复
现在的dos不包含这个sound函数了?
modyaj 2013-09-01
  • 打赏
  • 举报
回复
sound 等着几个函数的头文件包含了么?
nextseconds 2013-09-01
  • 打赏
  • 举报
回复
包含他们的头文件进去

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧