如何将声音添加到C ++控制台应用程序?

时间:2021-10-06 20:35:19

I am trying to play audio like this:

我正在尝试播放这样的音频:

    #include <iostream>
    #include <windows.h>
    #include <mmsystem.h>
    int main()
    {

        PlaySound(TEXT("I_Dare_You (1).mov"), NULL, SND_FILENAME);
        system("PAUSE");
        return 0;
    }

When I compile it, I get these errors:

当我编译它时,我得到这些错误:

    LNK1120 1 unresolved externals
    LNK2019 unresolved external symbol __imp__PlaySoundW@12 referenced in function _main

Why do I get these errors, and how do I fix them?

为什么我会收到这些错误,如何解决?

1 个解决方案

#1


0  

If you look at the Microsoft documentation for PlaySound you'll see that the library referenced for this function is WinMM.lib. Add that file to your project, the path to it should already be part of your configuration.

如果您查看PlaySound的Microsoft文档,您将看到为此函数引用的库是WinMM.lib。将该文件添加到项目中,它的路径应该已经成为您配置的一部分。

#1


0  

If you look at the Microsoft documentation for PlaySound you'll see that the library referenced for this function is WinMM.lib. Add that file to your project, the path to it should already be part of your configuration.

如果您查看PlaySound的Microsoft文档,您将看到为此函数引用的库是WinMM.lib。将该文件添加到项目中,它的路径应该已经成为您配置的一部分。