Making it beep in c++ - c++

I've recently picked up C++ and I am using a Mac with Xcode to start learning.
One of the problems I am having is making it BEEP!!
I know there is a lot of StackOverflow questions for this and the most popular seems to be std::cout << "\007"
#include < iostream >
int main() {
std::cout << "\007";
return 0;
}
Is there something I am missing?

Try cout << '\a' << flush; instead. You can make a system call like system("say beep"); but this is very OS dependent and will not work on all machines.

Related

Build OpenCV with OpenCL support

in CMake, I built OpenCV with OpenCL Enable ON(It automatically detected the OPENCL_INCLUDE_DIR path but the OPENCL_LIBRARY was empty, even after clicking config. for OPENCL_LIBRARY i don't see browse button either .. after generating opencv binaries then i run the below code
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>
int main()
{
if (!cv::ocl::haveOpenCL())
cout << "OpenCL is not avaiable..." << endl;
else cout << "OpenCL is AVAILABLE! :) " << endl; //this is the output
cv::ocl::setUseOpenCL(true);
cout << context.ndevices() << " GPU devices are detected." << endl;
for (int i = 0; i < context.ndevices(); i++)
{
cv::ocl::Device device = context.device(i);
cout << "name: " << device.name() << endl;
cout << "available: " << device.available() << endl;
cout << "imageSupport: " << device.imageSupport() << endl;
cout << "OpenCL_C_Version: " << device.OpenCL_C_Version() << endl;
cout << endl;
} //this works & i can see my video card name & opencl version
cv::ocl::Device(context.device(0));
}
When i make use of UMat to measure the performance, the performance with(UMat) or without(Mat) OpenCL did not make any difference.
I downloaded AMD-APP-SDK from this link and tried to build but there was no OpenCL binaries (instead i saw opengl dll files[glew32.dll & glut32.dll]. How do i build OpenCV with OpenCL by linking the OPENCL_LIBRARY?
I believe you have OpenCL, hence the result of your call to haveOpenCL and from the version request. I'm not sure the results of your performance test equate that you don't have OpenCL.
If you want to understand OpenCL, I would take a step back and figure it out first and then try to understand OpenCV with it.
Your link didn't work, did you try this. It has a link to the current AMD APP SDK (3.0) I would go through that setup and make sure you can make the OpenCL samples build/work on your system and then you should be able to troubleshoot why it isn't working in OpenCV (if it truly isn't).
As to performance, well, it depends. Every time you send data to and from the the graphics card it comes at a cost; the Transparent API was designed to make that choice for you: if sending it to the card for faster processing is worth the trip there and back... if it is not worth the trip you will actually have poorer performance. Additionally, not all of the library will run on the GPU. See some of the explanation on opencv.org.

Making a C++ application "Opened with..."

I'm working on a (C++) program that more or less revolves around renaming files. I would like to make it so that you can select a file, right-mouse click it and select "Open With" and then select my application.
I got the context menu part figured out, I just don't know how to do the C++ part.
In other words, how to make a program (in C++) that can be opened together with a file (so by context menu or directly opening it) and process this file?
Example:
In my Windows, I associate the ".roberto" extension with "C:\Program Files\MyProgram\MyProgram.exe". So if I open a ".roberto" file, a command prompt pops up, only displaying the name of the selected file.
I hope this is clear, I am not sure how to explain this. I also had some trouble with searching on this question, so please forgive me if this has been asked before.
Thanks.
On Windows platform in MFC-based application this is done automatically by framework in InitInstance() method of your application class:
EnableShellOpen();
RegisterShellFileTypes(TRUE);
IMPORTANT: In general this functionality is framework dependent and OS speicific.
I figured it out!
Using the arguments given to main was the clue. The following program prints one line if opened directly, this line is the path of the program itself, and if opened with the 'Open with...' options it also shows the selected file.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout << "Argument count: " << argc << endl << endl;
for (int i = 0; i < argc; i++)
{
cout << argv[i] << endl;
}
cout << endl << endl << endl << endl;
system("pause");
return 0;
}

Command processor has stopped working

I was writing a code for exception handling on Visual C++ 2010 .Here is the code
#include <iostream>
using namespace std;
// Localize a try/catch to a function.
void Xhandler(int test)
{
try{
if(test) throw test;
}
catch(int i) {
cout << "Caught Exception #: " << i << '\n';
}
}
int main()
{
cout << "Start\n";
Xhandler(1);
Xhandler(2);
Xhandler(0);
Xhandler(3);
cout << "End";
return 0;
}
The Program executed properly and the output was the as expected.But when I pressed the close button for closing the console then an error came that cmd has stopped working
.Then I ran my previous code that executed properly ,they also gave the same error
.
Can anybody tell why it is happening?Is it a problem with the Visual c++ 2010 or the code
I think your problem is not with your code. The problem is within your compiler tool chain. You probably are using Qt, and the tool chain has a problem causing this. Google the message you get when you crash with your IDE.
Here's a simple experiment to prove what I'm saying: just run this code:
int main()
{
cout << "Start\n";
cout << "End";
return 0;
}
And your program will crash, which means you have no problems with exceptions or anything else in your code, but with your tool chain.

How do I get PCRE to work correctly with Code::blocks?

I am facing some problems while working with PCRE in Code::blocks. I have downloaded PCRE from here. And did all the steps mentioned here. However I am getting a pcr3.dll missing error during execution.
The program can't start because pcre3.dll is missing from your
computer. Try reinstalling the program to fix this problem.
My code:
#include <iostream>
#include <regex.h>
using namespace std;
int main(){
regex_t reg;
string pattern = "[^tpr]{2,}";
string str = "topcoder";
regmatch_t matches[1];
regcomp(&reg,pattern.c_str(),REG_EXTENDED|REG_ICASE);
if (regexec(&reg,str.c_str(),1,matches,0)==0) {
cout << "Match " ;
cout << str.substr(matches[0].rm_so,matches[0].rm_eo-matches[0].rm_so) ;
cout << " found starting at: " ;
cout << matches[0].rm_so ;
cout << " and ending at " ;
cout << matches[0].rm_eo ;
cout << endl;
} else {
cout << "Match not found.";
cout << endl;
}
regfree(&reg);
return 0;
}
I am not sure how to fix this, any ideas?
PS: Above mentioned code is taken from this tutorial.
Copy the DLL to the same directory as the executable that you are running. If that works, you didn't install the DLL correctly or at least not in a way that it can be found by the programs in general. Check out the documentation of the DLL Search Order to get an idea how else you can make the system find the DLL. In particular, you need to know that there is a linker and a loader (aka dynamic/runtime linker/loader), but only one of them is configured inside CodeBlocks!

Get ID from MIDI devices in C++

I'm a musician and a programmer and would like to create my own program to make music.
I'll start with a console application in C++ before I make a GUI.
I'm quiet new to C/C++ and know how to make a basic console application and have read about the Win32 API.
I was looking into MSDN for multimedia in Win32 applications and I found a lot of functions for MIDI: http://msdn.microsoft.com/en-us/library/dd798495(VS.85).aspx
I can receive how many MIDI devices are plugged in this way:
#include <windows.h>
#include <iostream>
using namespace std;
int main() {
cout << midiInGetNumDevs();
cout << " MIDI devices connected" << endl;
return 0;
}
But now i want to find out how these devices are called, with the midiInGetID function I think and a while loop. Can somebody help me with this? The function requires a HMIDIIN parameter and I don't know how I can get one since almost all the MIDI functions use this parameter.
I know this is not the most obvious topic but it would be great if someone could help me.
Thanks :)
To get information, you loop calling midiInGetDevCaps, with a first parameter varying from 0 included to the result of midiInGetNumDevs excluded. Each call fills a MIDIINCAPS struct (you pass a pointer to the struct when you call the function) with information about the Nth device. To open a device, and fill the HMIDIIN needed for other calls, you call midiInOpen with the device number (again, 0 to N-1 included) as the second parameter.
The same concept applies to output devices, except that the names have Out instead of In (and for the structures OUT instead of IN).
Ok I figured it out. I didn't know midiInGetDevCaps requires a call to the specific properties of it to return the device name.
Here is my code:
#include <windows.h>
#include <iostream>
using namespace std;
int main() {
unsigned int devCount = midiInGetNumDevs();
cout << devCount << " MIDI devices connected:" << endl;
MIDIINCAPS inputCapabilities;
for (unsigned int i = 0; i < devCount; i++) {
midiInGetDevCaps(i, &inputCapabilities, sizeof(inputCapabilities));
cout << "[" << i << "] " << inputCapabilities.szPname << endl;
}
}
And thanks for your help!