c++

String to wstring conversion on OS X

Hello, I'm trying to convert a C++ string to a wstring. I found the following code, that seems to deal with accents, which is what I'm looking for. std::wstring widen(const std::string& s) { std::vector<wchar_t> buffer(s.size()); std::locale loc("fr_FR"); std::use_facet< std::ctype<wchar_t> >(loc).widen(s.data(), s.data() + ...

QProgressbar and QNetworkReply signals

Hello, i'm writing an application in C++ with the Qt Framework. It should download a File over http and display the download progress with a QProgressbar - but I don't get that part to work! Sample code: QProgressBar* pbar = new QProgressBar(); //calls the website and returns the QNetworkReply* QNetworkReply* downloader = Downloader->...

C++ namespaces - "using" or explicitly stated?

Possible Duplicates: Why is using namespace std; considered a bad practice in C++? Using std Namespace Is it just a matter of preference? Or is there a valid reason for preferring using namespace std; #include <string> myString string; or #include <string> myString std::string; I suppose that explicitly stating the name...

Extract individual images (QImage) from a video stream in Qt

I have successfully written a Qt program to play a video from a RTP stream (or other sources). I am using the Phonon classes MediaObject and VideoWidget. My question is: how can I gain access to the individual frames? I wanted to do motion detection by differencing successive frames. Many thanks for your advice. wpoet. ...

implicit linking DLL question

I started studying DLL's with implicit linking. I don't really fully understand how it works. Please correct me where I'm wrong. I failed to compile the next code(3 modules): MyLib.h #ifdef MYLIBAPI #else #define MYLIBAPI extern "C" __declspec(dllimport) #endif MYLIBAPI int g_nResult; MYLIBAPI int Add(int nLeft, int nRight); ...

Is there an algorithm for moving ranges?

In C++98, I can copy ranges with the std::copy algorithm. std::copy(source.begin(), source.end(), destination.begin()); Is there an algorithm in C++0x that moves the elements from source to destination? Or is std::copy somehow overloaded to accept something like rvalue iterators -- is there even such a thing? The algorithm might look...

Open a dialog box from a DLL

I have a Visual Studio 2008 solution with two projects: a C# Windows Forms application and a C++ DLL. The DLL opens a custom CFileDialog. Here is a toy version that demonstrates the problem, where the C# app is just a button to launch the dialog and a label to show its result: DialogApp.cs: ... public partial class Form1 : Form { ....

How to orbit around the Z-axis in 3D

Hello folks, I'm primarily a Flash AS3 dev, but I'm jumping into openframeworks and having trouble using 3D (these examples are in AS) In 2D you can simulate an object orbiting a point by using Math.Sin() and Math.cos(), like so function update(event:Event):void { dot.x = xCenter + Math.cos(angle*Math.PI/180) * range; dot.y = y...

Learning C++ right?

Since I have been mostly using script languages in the past time but now want to go to the "high-performance" level I decided to learn C++ some time ago. I looked at some "beginner" tutorials and bought an O'reilly C++ pocket reference book (it's really helpful). My problem is that I now know all the basics but I'm not good enought to p...

Local classes inside inline non-member function produces LNK2005 with MSVC2005

Apparently, MSVC2005 fails to inline local classes' member functions which leads to LNK2005. I'm facing this LNK2005 error when compiling the following: common.h content: inline void wait_what() { struct wtf { void ffffuuu() {} } local; } foo.cpp content: #include "common.h" void foo() { wait_what(); } bar.cpp conte...

Help in converting AA script to C++

Hi, I've this AA script (Cheat Engine scripting language): [ENABLE] alloc(newmem,2048) //2kb should be enough label(returnhere) label(exit) 00415e19: jmp newmem returnhere: newmem: mov [00451104],0//moves 0 to the clock variable //nop//nops the clock increaser exit: jmp returnhere [DISABLE] dealloc(newmem) 00415e19: mov [00451104],e...

Efficient Way to Process Simple but Large Files in C++

I'm working on a project that has me a bit over my head performance-wise. I'm tasked with reading large (50MB or so) files of particle coordinates and displaying them. I'd like to use C++ for this because I am learning it already. The coordinate structure in the files are simple, there's just alot (say a million or so): 1234.5667...

Resources to Write ANSI C++ Code

The last time I heavily used C++ was years ago, and it was strictly done on the Windows platform. Specifically, I used Microsoft Visual Studio as my IDE and developed some habitual patterns to use Microsoft's C++ version. For example, I used void main() instead of the standard int main(). Now, I am taking a class where it is required ...

How to use boost normal distribution classes?

Hi all, I'm trying to use boost::normal_distribution in order to generate a normal distribution with mean 0 and sigma 1. The following code doesn't work as some values are over or beyond -1 and 1 (and shouldn't be). Could someont point out what I am doing wrong? #include <boost/random.hpp> #include <boost/random/normal_distribution.hpp...

Why aren't there compiler-generated swap() methods in C++0x?

C++ compilers automatically generate copy constructors and copy-assignment operators. Why not swap too? These days the preferred method for implementing the copy-assignment operator is the copy-and-swap idiom: T& operator=(const T& other) { T copy(other); swap(copy); return *this; } (ignoring the copy-elision-friendly for...

How can I decode HTML entities in C++?

How can I decode HTML entities in C++? For example: HTML: &quot;Music&quot; &amp; &quot;video&quot; Decoded: "Music" & "video" Thanks. ...

question about throwing an object

#include <iostream> using namespace std; class A{ public: A() {std::cout<<"A() ";} A(const A& a){cout<<"A(const A&) ";} ~A(){cout<<"~A() ";} virtual void Foo(){cout<<"A::Foo() ";} }; class B: public A { public: B(){std::cout<<"B() ";} B(const B& a){cout<<"B(const B&) ";} ~B(){cout<<"~B() ";} virtual vo...

Odd Memory Error -- Bad Alloc

Working on a WinPCap project. Trying to do some basic pointer and memory operations and having lots of errors. I've included the two lines I'm trying to run along with the includes. The same lines in another VSC++ project work just fine. This is the error I am getting Unhandled exception at 0x75a79617 in pktdump_ex.exe: Microsoft ...

OpenCV's clustering function cvKMeans2() - what is a type of cluster center in array?

I'm using function cvKMeans2() from OpenCV library for clustering. It has optional parametr: centers - The optional output array of the cluster centers The same parametr is also in function kmeans(). I want to know informations about clusters. But I haven't found what is a type of that cluster center in array, so I can't get it. Thanks...

Cannot Modify Non Const Member in Class

Hi, I try to modify one specific method in OpenCV. In the class definition; class CV_EXPORTS CvANN_MLP : public CvStatModel ... protected ... int activ_func; when I try to modify activ_func field, I get: error: assignment of data-member in read-only structure error, however it is not defined as const, how is that possible? ...