看了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 );
下面是我将书上的试一试实现的程序:
// 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; }