c++

Accurate continuous timer callback

Ive got an application where I want to display a frame every x milliseconds. Previously I did it like this: class SomeClass { boost::thread thread_; boost::timer timer_; public: SomeClass() : thread_([=]{Display();}) { } void Display { double wait = 1.0/fps*1000.0; while(isRunning_...

Unable to create/save output avi file in OpenCV

I Have following source code to detect BLOB and i am using MS 2008 , OpenVC 2.1 #include "stdafx.h" #include <cv.h> #include <highgui.h> #include <stdio.h> #include <stdlib.h> using namespace std; /*You may change the values of the sthreshold and hlower and hupper to get different results....*/ const int sthreshold=210; const double h...

Sometimes I get EXEC_BAD_ACCESS (Access violation) when reversing an array

Hello, I am loading an image using the OpenEXR library. This works fine, except the image is loaded rotated 180 degrees. I use the loop shown below to reverse the array but sometimes the program will quit and xcode will give me an EXEC_BAD_ACCESS error (Which I assume is the same as an access violation in msvc). It does not happen every...

measure texts code from programming pearls

I have this code from programming pearls #include <iostream> //#include <string> using namespace std; template <class T> void measure(char *text) { cout<<"measure"<<text<<"\t"; cout<<sizeof(t)<<"\n"; } #define MEASURE(T,text){ cout<<text<<"\t"; cout<<sizeof(T)<<"\t"; int lastp=0; for (int i=0;i<11;i++){ T *p=new T; ...

Including C headers inside a C++ program

I have a C++ program (.cpp) inside which I wish to use some of the functions which are present inside the C header files such as stdio.h, conio.h, stdlib.h, graphics.h, devices.h etc. I could include the stdio.h library inside my cpp file as : #include <cstdio>. How do I include the other library files? How do I add the graphics.h libr...

Player/Stage- robot is not moving in simulaion?

Hi, I am new to player/stage. But somehow I managed to come up with the below code but is not moving First the configuration file driver ( name "stage" provides ["simulation:0"] plugin "stageplugin" #load the world file worldfile "robotWorld.world" ) driver ( name "stage" provides [ ...

Is it possible to force a function not to be inlined?

I want to force a little function not to be compiled as inline function even if it's very simple. I think this is useful for debug purpose. Is there any keyword to do this? ...

Where can I learn how to make a C++ program interact with the Operating System (Linux)

I am a C++ beginner. I'd like to create small programs that interact with the operating system (using Kubuntu Linux). So far, I have not been able to locate any tutorial or handbook to get C++ to interface with the OS. In PHP, I can use the command exec() or the backtick operator to launch commands typically executed in a console. How ...

Stange error with preprocessor macro

i have changed code style and aslo i hope it will help http://www.cs.bell-labs.com/cm/cs/pearls/spacemod.cpp #include <iostream> using namespace std; #define MEASURE(T, text) { \ int i; cout<<text<<"\t"; \ cout<<sizeof(T)<<"\t"; \ int lastp=0;\ for ( i=0;i<11;i++){ ...

Container that doesn't require its elements to be default and copy constructible

I'm looking for a C++ container-like class that wraps a typed array of objects that are not necessarily initialized and don't have to be default-constructible or copy-constructible. This would be interesting for RAII objects that have no well-defined copy semantics. Such a container-like class seems to be fairly easy to write (using an a...

How to use CURL(pp) (wrapper)

How can I use Curlpp (or clean CURL)? Now, I'm trying to do few basic actions (for example use POST) and I can't compile my project (now, I am using Windows, mingw, code::blocks). I have added library, my IDE see this library. I heard about problems with curl+mingw+code::block. Solution is using definition #define STDC_HEADRES 1 in cu...

Calculating the Moment Of Inertia for a concave 2D polygon relative to its orgin.

Hi, I want to compute the moment of inertia of a (2D) concave polygon. I found this on the internet. But I'm not very sure how to interpret the formula... 1) Is this formula correct? 2) If so, is my convertion to C++ correct? float sum (0); for (int i = 0; i < N; i++) // N = number of vertices { int j = (i + 1) % N; sum += (...

Thunk and ATL Thunk?

Can someone explain to me what a Thunk is? and an ATL Thunk? I know a thunk has something to do with the vtbl and execution of code to find the right function pointer. Am I right? ...

Generating two independent random number sequences (C++)

I'd like to be able to do something like this (obviously not valid C++): rng1 = srand(x) rng2 = srand(y) //rng1 and rng2 give me two separate sequences of random numbers //based on the srand seed rng1.rand() rng2.rand() Is there any way to do something like this in C++? For example in Java I can create two java.util.Random objects wi...

Exception within function returning value for constructor...

Let's say I have class that acts as a "smart pointer" and releases some kind of system resource when destroyed. class Resource{ protected: ResourceHandle h; public: Resource(ResourceHandle handle) :h(handle){ } ~Resource(){ if (h) releaseResourceHandle(h);//external function, probably from...

Loan calculator alteration.

Hi everyone! I created a program that calculates loans, but it doesn't go under the guidelines of what my professor asked. Can show me the correct alteration. Source Code would be awesome and time saving, but you don't have to. Heres the problem: Write a program that lets the user enter the loan amount and the loan period in number of ...

"Multiple occurrences" exception for boost program_options

Hello, I am writing the following code on boost's program_options (version 1.42). This seems straight-forward and taken pretty much as is from the tutorial. However, I get a "multiple_occurrences" error. Further investigation discovers that it's (probably) the "filename" parameter that raises it. The parameters I am giving are: 3 1 te...

File Local Define

Hey all; This question more falls into the category of best practices, and clean/safe code for distribution. I'm working on a math library in c++, for my portfolio, and to use during my last two semesters of College. I want this library to be very easy to use, and to minimize the possibilities of conflicts with pre existing code. For...

utfcpp and Win32 wide API

Is it good/safe/possible to use the tiny utfcpp library for converting everything I get back from the wide Windows API (FindFirstFileW and such) to a valid UTF8 representation using utf16to8? I would like to use UTF8 internally, but am having trouble getting the correct output (via wcout after another conversion or plain cout). Normal A...

C++ ifstream UTF8 first characters

Why does a file saved as UTF8 (in Notepad++) have this character in the beginning of the fstream I opened to it in my c++ program? ´╗┐ I have no idea what it is, I just know that it's not there when I save to ASCII. UPDATE: If I save it to UTF8 (without BOM) it's not there. How can I check the encoding of a file (ASCII or UTF8, ev...