我的代码对不对?(c++中添加声音)

来源:百度知道 编辑:UC知道 时间:2024/05/30 15:14:38
请高手指点指点,哪里出错了,怎么改,如果播放其他格式的音频文件可以吗(mp3、rm...)
代码如下:
#include <iostream>
#include <windows.h>
#include "mmsystem.h"//导入声音头文件
#pragma comment(lib,"winmm.lib")//导入声音头文件库
using namespace std;

void main ()
{

PlaySoundW ("D:\\english songs\\big big world..wav",NULL, SND_LOOP );

}

错误提示:
d:\my documents\visual studio 2005\projects\sdfa\sdfa\main.cpp(9) : error C2664: “PlaySoundW”: 不能将参数 1 从“const char [12]”转换为“LPCWSTR”
与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
问题解决了,但是只能播放*.wav格式,其它格式的怎么播放?

当然是错的。
PlaySound (_T("D:\\english songs\\big big world.wav"),NULL, SND_LOOP );
用_T()宏可以将其转换为LPCWSTR.但是注意是WIN32开发环境
在控制台下面请用这个:
PlaySound (L"D:\\english songs\\big big world.wav",NULL, SND_LOOP );
LS的简直一窍不通。

PlaySound ("D:\\english songs\\big big world.wav",NULL, SND_LOOP );

你用的PlaySoundW是宽字符版的函数