c++

C++ Mysql Real Escape String Issue

Hmm, for some reason, its only doing this on the first username (and password) and does it for how big my my vector is. Any ideas on why? int eMysql::strip(string &input) { char* from = new char[strlen(input.c_str()) * 3 + 1]; mysql_real_escape_string(&mysql, from, input.c_str(), input.length()); input = input.assign(from); ...

Help me translate Python code which replaces an extension in file name to C++.

I apologize if you know nothing about Python, however, the following snippet should be very readable to anyone. The only trick to watch out for - indexing a list with [-1] gives you the last element if there is one, or raises an exception. >>> fileName = 'TheFileName.Something.xMl' >>> fileNameList = fileName.split('.') >>> assert(len(f...

Can CMake generate build scripts which do *not* use cmake?

Question: Can CMake generate build scripts that do not, in any way, use CMake? If not, how hard is it to gut a CMake generated automake script to not make any checks against CMake? I am a big fan of CMake to the point where I am championing the idea that we transition to it in my current work environment. One thing that could ease this ...

C++ Pass By Const Reference and Return By Const Reference

I'm trying to understand if there is any benefit to returning a const reference. I have a factorial function that normally looks like this: unsigned long factorial(unsigned long n) { return (n == 0) ? 1 : n * factorial(n - 1); } I'm assuming that there will be a performance increase when we pass by const reference and we return a ...

Shared pointers and building in SIP4 (was: Dynamic casting in SWIG/python?)

So I'm playing about with Python, C++0x, and SWIG 2.0. I've got a header that looks like this: #include <string> #include <iostream> #include <memory> using namespace std; struct Base { virtual string name(); int foo; shared_ptr<Base> mine; Base(int); virtual ~Base() {} virtual void doit(shared_ptr<Base> b) { cout << ...

ReadFile() Output to WinAPI edit Dialog

Ok, let's see if this all makes sense. Today, as I began working on a small project, I ran into an error I can't seem to get over. The function of the program I am working on is to read data from a pipe (which is the output of another program) and update an HWND ("edit") control dialog using WinAPI. Now, I've been successful at updating ...

Strange behavior with static template'd class.

Hello, I've been having some difficulties with diagnosing a segmentation fault resulting from, or at least I think resulting from a template'd static class (see original post here http://stackoverflow.com/questions/3200360/help-understanding-segfault-with-stdmap-boostunordered-map). Since posting that I found some other bizarre behavio...

How to look at the data stored in a QMap?

How to look at the data stored in QMap without iterating through it? I am trying to debug an application using QMap with many keys, do you know a way to look at the data in QMap without iterating through each value? ...

[Win32] Adding items to a ListView?

I'm having trouble adding items onto a ListView control. When I try to add items to my ListView, nothing happens. I was using this code before, and it didn't work. I have 3 columns, with the SubItem values set to 1, 2, and 3. LVITEM item; item.mask = LVIF_TEXT; item.cchTextMax = 6; item.iSubItem = 1; item.pszText = TEXT...

clean C++ granular friend equivalent? (Answer: Attorney-Client Idiom)

Why does C++ have public members that anyone can call and friend declarations that expose all private members to given foreign classes or methods but offer no syntax to expose particular members to given callers? I want to express interfaces with some routines to be invoked only by known callers without having to give those callers comp...

Breaking a "for" loop using "break" considered harmful?

Possible Duplicate: Break statements In the real world Some days ago I started a quick open source project and, when some mates looked at the code on svn, one of them told me that using break statement inside a for loop is considered harmful and shouldn't be done. He added, though, that I would find several cases of break st...

Why does my C++ subclass need an explicit constructor?

I have a base class that declares and defines a constructor, but for some reason my publicly derived class is not seeing that constructor, and I therefore have to explicitly declare a forwarding constructor in the derived class: class WireCount0 { protected: int m; public: WireCount0(const int& rhs) { m = rhs; } }; class WireCo...

Accessing Mozilla's ISimpleDOMNode by using IAccessible

I have the following code: IAccessible *pAccessible = NULL; IServiceProvider *pServProv = NULL; AccessibleObjectFromWindow((HWND)0x0025093A, OBJID_CLIENT, IID_IAccessible, (void**)&pAccessible); HRESULT hr = pAccessible->QueryInterface(IID_IServiceProvider, (void**)&pServProv); if (SUCCEEDED(hr) && (pServProv != NULL)) { const GUI...

Why is this array selection causing such a glitchy phenomenon?

I was loading a image in openGl with the Glaux library when I came across a very strange phenomenon with a array. Some example of what I tried and if they succeeded or not are below. The curFreeId variable is global. The extra variables I created to test with are local to the function. Since when does this effect the flow of code. ...

Continously Read/Write Data with Pipes Win32

Hello, I am trying to write a GUI program for a command line program in Win32 using WinAPI (so please no MFC). In my current attempt, I am creating an input pipe and an output pipe to read/write data. However, my problem comes in when I attempt to continuously read from a program or to simply write after a single read due to the way I h...

C++ program converts fahrenheit to celsius

Can someone help me understand why this gives an output of 0? #include <iostream> using namespace std; int main() { float celsius; float fahrenheit; cout << "Enter Celsius temperature: "; cin >> celsius; fahrenh...

Bin packing implementation in C++ with STL

This is my first time using this site so sorry for any bad formatting or weird formulations, I'll try my best to conform to the rules on this site but I might do some misstakes in the beginning. I'm right now working on an implementation of some different bin packing algorithms in C++ using the STL containers. In the current code I stil...

Enable Exception C++

Hi. I am trying to make APP native code for Android. The Native code is in cplusplus. Whenever I try to make, the following error appears. H236Plus.cpp:135: error: exception handling disabled, use -fexceptions to enable How do I use -fexceptions to enable exception handling, and where do i use it? ...

when to use new in C++?

What's a good policy for when to use "new" to make an instance of a class? I've been hobby programming C++ for a while but I'm still not for sure when is the best time to do this: MyClass thing(param1, param2); over this: MyClass* thing; thing = new MyClass(param1, param2); Any advice? ...

Matrix Transformation Problem - Z Axis Rotation is Skewing

For a simple 2d game I'm making I'm trying to rotate sprites around the z axis using matrices. I'm clearly doing something wrong as when I attempt to rotate my sprite it looks like it's being rotated around the screen origin (bottom, left) and not the sprite origin. I'm confused as my quad is at the origin already so I didn't think I nee...