c++

Multiset container appears to stop sorting

I would appreciate help debugging some strange behavior by a multiset container. Occasionally, the container appears to stop sorting. This is an infrequent error, apparent in only some simulations after a long time, and I'm short on ideas. (I'm an amateur programmer--suggestions of all kinds are welcome.) My container is a std::multiset...

(static initialization/template instantiation) problems with factory pattern

Why does following code raise an exception (in createObjects call to map::at) alternativly the code (and its output) can be viewed here intererestingly the code works as expected if the commented lines are uncommented with both microsoft and gcc compiler (see here), this even works with initMap as ordinary static variable instead of sta...

Get updated size of QGraphicsView

Hi, In my Qt Application I am dynamically creating QGraphicsView(s) and adding them inside a QGridLayout. When I add first view inside grid, the view covers all the available space inside grid. Then I add second view and there are now two equally sized views inside grid. Then I add third view and there are now three equally sized views ...

priority queue clear method

How do I delete all elements from a priority queue? That means how do I destroy a priority queue? advanced thanks for your answer. Is there any clear- or erase-like method? ...

Loop through hex variable in C

I have the following code in a project that write's the ascii representation of packet to a unix tty: int written = 0; int start_of_data = 3; //write data to fifo while (length) { if ((written = write(fifo_fd, &packet[start_of_data], length)) == -1) { printf("Error writing to FIFO\n"); } else { ...

using scanf in C/C++

To read an int using scanf we use: scanf("%d",&i); What if i is long not int?? Note: when using %d with long it gives me an irritating warning.. Thanks! ...

Using an initializer_list on a map of vectors

I've been trying to initialize a map of <ints, vector<ints> > using the new 0X standard, but I cannot seem to get the syntax correct. I'd like to make a map with a single entry with key:value = 1:<3,4> #include <initializer_list> #include <map> #include <vector> using namespace std; map<int, vector<int> > A = {1,{3,4}}; .... It dies...

Boggling Direct3D9 dynamic vertex buffer Lock crash/post-lock failure on Intel GMA X3100.

Hi, For starters I'm a fairly seasoned graphics programmer but as wel all know, everyone makes mistakes. Unfortunately the codebase is a bit too large to start throwing sensible snippets here and re-creating the whole situation in an isolated CPP/codebase is too tall an order -- for which I am sorry, do not have the time. I'll do my bes...

Protecting Content Files

Hello, I want a simple layer of protection for my content (resource) files in my application. For example, I have various sound and image files used in my application. I think, I can wrap them in a SFX archive (Probably packed with WinRAR), then in my application, start the SFX exe with some parameters, like, -silent. But this may not b...

C++ program runs slow in VS2008

I have a program written in C++, that opens a binary file(test.bin), reads it object by object, and puts each object into a new file (it opens the new file, writes into it(append), and closes it). I use fopen/fclose, fread and fwrite. test.bin contains 20,000 objects. This program runs under linux with g++ in 1 sec but in VS2008 in debu...

GetDeviceGammaRamp to adjust colors

Hi, I overlay an OpenGL application (c++), this openGL application uses SetDeviceGammaRamp to set the brightness of the desktop to very high (dont know why). This application is fullscreen and looks good, but my overlay is very bright. Instead of the orange color with normal brightness, I get yellow because of the high gamma. What I wa...

Wrong reading file in UNICODE (fread) on C++

Hello, I'm trying to load into string the content of file saved on the dics. The file is .CS code, created in VisualStudio so I suppose it's saved in UTF-8 coding. I'm doing this: FILE *fConnect = _wfopen(connectFilePath, _T("r,ccs=UTF-8")); if (!fConnect) return; fseek(fConnect, 0, SEEK_END); lSize = ftell(fConnect)...

boost lambda versus phoenix

hello. I recently started looking at boost phoenix, as replacement for lambda. Is phoenix a full replacement for lambda, or is there some lambda functionality which is not provided by phoenix? is phoenix mature? Are there any gotcha I should know about? my primary interest are operator composition, control statements and casts are les...

Is this a memory leak?

char *pointer1; char *pointer2; pointer1 = new char[256]; pointer2 = pointer1; delete [] pointer1; In other words, do I have to do delete [] pointer2 as well? Thanks! ...

pointer delegate in STL set.

I'm kinda stuck with using a set with a pointer delegate. My code is as follows: void Graph::addNodes (NodeSet& nodes) { for (NodeSet::iterator pos = nodes.begin(); pos != nodes.end(); ++pos) { addNode(*pos); } } Here NodeSet is defined as: typedef std::set<Node_ptr, Node_ptr_Sorting_Predicate> NodeSet; The above piece...

Problems compiliing c++ code using cygwin

I am trying to compile some source code in cygwin (in windows 7) and get the following error when I run the make file g++ -DHAVE_CONFIG_H -I. -I.. -I.. -Wall -Wextra -Werror -g -O2 -MT libcommon_a Fcntl.o -MD -MP -MF .deps/libcommon_a-Fcntl.Tpo -c -o libcommon_a-Fcntl.o `test -f 'Fcntl.cpp' || echo './'`Fcntl.cpp Fcntl.cpp: In functi...

C++ iterate or split UTF-8 string into array of symbols?

Searching for a platform- and 3rd-party-library- independent way of iterating UTF-8 string or splitting it into array of UTF-8 symbols. Please post a code snippet. Solved: http://stackoverflow.com/questions/2852895/c-iterate-or-split-utf-8-string-into-array-of-symbols#2856241 ...

problem finding a header with a c++ makefile

Hi. I've started working with my first makefile. I'm writing a roguelike in C++ using the libtcod library, and have the following hello world program to test if my environment's up and running: #include "libtcod.hpp" int main() { TCODConsole::initRoot(80, 50, "PartyHack"); TCODConsole::root->printCenter(40, 25, TCOD_BKGND_NON...

What exactly does an #if 0 ..... #endif block do?

In C/C++ What happens to code placed between an #if 0/#endif block? #if 0 //Code goes here #endif Does the code simply get skipped and therefore does not get executed? ...

Purpose of boost::checked_delete

I don't understand the purpose of boost::checked_delete. The documentation says: The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to be deleted with a delete-expression. When the class has a non-trivial destructor, or a class-specific operator delete, the behavior is undefined. Some compilers issue...