我想用 C++ 制作一架简单的钢琴。我将检查用户是否按下键盘上的键并播放钢琴声。按键声音在桌面上下载,它们是 .mp3 文件。所以只是为了测试我写了这段代码:
#include "MyTestCodes.h"
//MyTestCodes.h Includes
/*
#include <iostream> //Input/Output Stream For Console
#include <string> //For String
#include <fstream> //File Stream
#include <vector> //Changable Index Structure
#include <Windows.h>//For System Commands
#include <algorithm>//Easy Sorting For Arrays/Vectors ...
#include <iomanip> //For Outputting With Given Precision
#include <cmath> //Easy Math Functions
#include <stdio.h> //Standart Input/Output For Given Types
#include <conio.h> //For Getting Key Presses
#include <ctime> //For Gettig Real Time
#include <filesystem>
#include <mmsystem.h>
#include <Mmsystem.h>
#include <mciapi.h>
*/
using namespace std;
#pragma comment(lib, "Winmm.lib")
int main(int argc, char* argv[])
{
PlaySound("C:/Users/niko/Desktop/key01 F.mp3", NULL, SND_FILENAME);
}
我也尝试过不使用
MyTestCodes.h
并自己包含其他库和头文件(我也自己写了 MyTestCodes.h
)。我主要包括那些:
#include <Windows.h>
#include <mmsystem.h>
#include <Mmsystem.h>
#include <mciapi.h>