1

below is the simple source code

#include <iostream>
using namespace std;

int main()
{
cout<<"Hello"<<endl;
system("pause");
return 0;
}??

how to let program play some music when the program
print the word "Hello"??
Let's say the song file name is "hello.mpg".

Edited by Dani: Formatting fixed

5
Contributors
7
Replies
20
Views
12 Years
Discussion Span
Last Post by 4reebahmedkhan
0
#include <stdmagic>

using namespace std;

int main()
{
  magically_do_something_platform_and_implementation_specific(PLAY_MUSIC, "hello.mpg");
}

By the way, what OS and compiler are you using? :rolleyes:

0

Not quite ZZ Top but it's a start!
The Windows Api has a little thing called Beep(), try it ...

// simple sounds via Beep(frequency_hrz, duration_ms)

#include <iostream>
#include <windows.h>   // WinApi header file

using namespace std;

int main(int argc, char *argv[])
{
  Beep(523.2511,500);  // 523.2511 hertz (C5) for 500 milliseconds
  Beep(587.3295,500);
  Beep(659.2551,500);
  Beep(698.4565,500);
  Beep(783.9909,500);
  
  cin.get(); // wait
  return 0;
}

There are nicer things like sound(), that use the sound chip and midi voices. A little tough for C++. If you want to test it, get BCX free from:

http://www.rjpcomputing.com/programming/bcx/devsuite.html

get used to BCXDX and learn to fly with sound and graphics! There are lots of sample files. This goes beyond the usual boring calculator and employee database stuff! You are still learning C/C++ though.

0

thx Vegaseat the program successdfully run and the beep sound is funny

0

Vegaseat do u know how to link the music or sound like "Hello.mpg"

when the compiler executed until cout<<"Hello"<<endl; and play some sound or music

0

you know, you can use the PlaySound function. you need to convert the audio file to a .wav file and you need to link winm.lib to your C++ file. and here is the code.

#include<windows.h>
#include<iostream>
int main(char argc)
{
    
       cout << "Hello" << endl;
       Sleep(50);
       PlaySound(TEXT("hello.wav"), NULL, SND_FILENAME);
       system("pause");
}

Edited by thecoolman5: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.