-1

Here is what I tried

#include <windows.h>
#include <mmsystem.h>
#pragma comment( lib, "Winmm.lib" )
using namespace std;

int main()
{
    PlaySound(L"C:\Users\Lol\Downloads\Music\Undertale OST - Hotel Extended.wav", 0, SND_FILENAME);
    return 0;
}

And it gives me an error:

incomplete universal character name \U|

Also before that it says:

ignoring #pragma comment [-Wunknown-pragmas]|

What is wrong here?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
LuckyFire
  • 41
  • 7

1 Answers1

3

incomplete universal character name \U|

In character and string literals, certain escape sequences have special meaning to the compiler:

escape sequences

Your string literal contains 2 instances of the \U escape sequence, however there are no numeric values following the \U to make up the digits of valid Unicode codepoints, hence the compiler error.

To use actual \ characters in your string literal, you need to escape them as \\, eg:

L"C:\\Users\\Lol\\Downloads\\Music\\Undertale OST - Hotel Extended.wav"

Or, if you are using C++11 or later, you can use a raw string literal, which uses a slightly different syntax that does not require you to escape characters manually:

LR"(C:\Users\Lol\Downloads\Music\Undertale OST - Hotel Extended.wav)"

ignoring #pragma comment [-Wunknown-pragmas]|

How you link to .lib files is very toolchain-specific. Your compiler (you did not say which one you are using) is telling you that it does not support the #pragma comment(lib, ...) directive. So, you will have to link to Winmm.lib in another way that is more appropriate for your particular toolchain's linker. Read the documentation for your toolchain.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I am a begginer at coding. I use CodeBlocks, and I found the code on another question in this site. Do you perhaps know how i can fix the pragma problem in CodeBlocks? – LuckyFire Apr 30 '20 at 20:24
  • @LuckyFire see [Using libraries with Code::Blocks](https://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/), and also see [#pragma comment](http://forums.codeblocks.org/index.php?topic=7238.0) in the [Code::Blocks](http://forums.codeblocks.org) forum – Remy Lebeau Apr 30 '20 at 20:43