学习C++之父的最新姐妹作笔记2
看了C++之父的最新作品也一段时间了,应该有半个月了,我是两本书一起看的,结合起来看的,个人认为这样看起来有助于理解,也看了好几章了,没有发现什么不大容易理解的地方,但有一个地方肯定是以前没有注意到的或者说没有接触到的。好,废话少说。
在原理与实践的71页“蜂鸣提醒”“BLEEP”,这两个词我想有很多人不知道去如何实现,至少我不明白。经过查找MSDN c++之父要说的是这个函数Beep(--,--)
具体函数说明如下:
BOOL WINAPI Beep( __in DWORD dwFreq, __in DWORD dwDuration );Parameters
- dwFreq
The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
Windows Me/98/95: The Beep function ignores this parameter.
- dwDuration
The duration of the sound, in milliseconds.
Windows Me/98/95: The Beep function ignores this parameter.
Return Value
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.
当然这个函数要包含头文件#include "windows.h"
Example:Beep( 750, 300 );
下面是我将书上的试一试实现的程序:
123456789101112131415161718192021222324252627282930313233343536373839404142434445// BLEEP.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
//这里我就懒得加载c++之父给我们写好的头文件了std_lib_facilities.h 因为都是比较常见的头文件
#include "windows.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using
namespace
std;
int
_tmain(
int
argc, _TCHAR* argv[])
{
vector<string> words;
string temp;
string disliked =
"Broccoli"
;
while
(cin>>temp)
{
if
(temp == disliked)
{
/*Beep 第一个参数 The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
第二个参数 The duration of the sound, in milliseconds.
*/
Beep(500,500);
break
;
}
words.push_back(temp);
}
cout<<
"Number of words: "
<<words.size()<<endl;
sort(words.begin(),words.end());
//#include <algorithm>
for
(
int
i = 0;i<words.size();i++)
{
if
(i==0||words[i-1]!=words[i])
{
cout<<words[i]<<endl;
}
}
system
(
"pause"
);
return
0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)