让U盘把内容写入文件,让播放器播放mpg 或avi视频

/* 案例4 从U盘到MP34
播放音乐
让U盘把内容写入文件,让播放器播放mpg 或avi视频
*/
////////////////////////////////////////////////////////////////
// "MP3"模拟程序
////////////////////////////////////////////////////////////////
#include<iostream>
#include<windows.h>
#include <mmsystem.h>
#include <fstream>
#pragma comment(lib,"winmm.lib")
using namespace std;
///////////////////////////////////////////////////////
// UDISK 窗口类,父类
///////////////////////////////////////////////////////
class UDISK
{
	private: //私有成员
		char *crow[100];
		int nrow;
	public:
		UDISK (void) //构造函数
		{
			nrow=0;
		}
		void read(void); //读数据
		void write(char *pstr); //写数据
};
//读数据
void UDISK ::read(void) //读数据
{
	int i=0;
	for(i=0;i<nrow;i++)
	{
		cout<<crow[i]<<endl;;
	}
}
//写数据
void UDISK ::write(char *pstr) //写数据
{
	ofstream out("E:\\U.txt");
	if (!out)
	{
		cout<<"Cannot open file.";
		exit(1);
	}
	crow[nrow]=pstr;	
	nrow++;

	int i=0;
	for(i=0;i<nrow;i++)
	{
		out<<crow[i];
	}
	
	out.close();
}
///////////////////////////////////////////////////////
// MP3 类,子类
///////////////////////////////////////////////////////
class MP3:public UDISK
{
	public:
		void play(char *pstr);
};
//MP3 播放
void MP3::play (char *pstr)
{
	char str[100]="play ";
	strcat(str,pstr);
	cout<<str;
	mciSendString(str,NULL,0, 0);
}
////////////////////////////////////////////////////////////////////////
//主函数
///////////////////////////////////////////////////////////////////////
int main()
{
	UDISK U1; //模拟U 盘
	cout<<"--模拟U 盘写--\n";
	U1.write (" 《劝学》 ");
	U1.write ("三更灯火五更鸡,");
	U1.write ("正是男儿读书时。");
	U1.write ("黑发不知勤学早,");
	U1.write ("白首方悔读书迟.。");
	cout<<"\n--模拟U 盘读--显示其内容--\n";
	U1.read ();
	MP3 M1; //模拟PM3
	cout<<"\n--模拟MP3 播放--\n";
	M1.play ("E:\\附2集合.wmv");
	char a;
	cin>>a; //输入任一字符,等待音乐播放
	return 0;
}

你可能感兴趣的:(音乐,mp3)