C++学习笔记——播放音乐

1、设置Dev C++编译器,工具->编译选项->编译器->在连接器命令行加入以下命令-lwinmm;
2、预先下载mp3歌曲,与可执行文件放在同一目录;
3、运行程序;

#include<iostream>
#include<windows.h>
#include<string.h>
#include<mmsystem.h> //媒体控制函数的头文件 
using namespace std;

int main(){
    
    
	char play[]="play "; //play后有空格 
	char song[]="甜蜜蜜.mp3";
	strcat(play, song);
	cout<<play<<endl;
	mciSendString(play,NULL,0,NULL);
	char c;
	cin>>c; //输入任意字符结束播放 
	return 0;
}

猜你喜欢

转载自blog.csdn.net/wxsy024680/article/details/113703996