c++

Priority Queue Not Sorting

Im trying to implement my own Huffman Coding algorithm and the priority queue for the C++ STL does not seem to be working correctly. I am taking characters from a string and inserting them into a priority queue by order of their frequency in the string. The code compiles and runs without error, the only thing is the tree seems to not be ...

API's similar to GLUTesselator?

I'm looking for an API that is open sourced and that can take contours of verticies as input and return verticies of triangles. I would also like it to support different winding rules. Thanks ...

C++ Auto Format

I am trying to create a program that auto formats my f:\ (USB Drive), and I have this code so far: #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <iostream> int main () { system ("format f:"); system("pause"); return 0; } Now, when I run that, it comes up, with me needing to press Y, then Enter. How can I ...

Program won't run in NetBeans, but runs on the command line!

So, I'm starting a C++ class right now, and I've configured NetBeans (which I use normally for PHP and Java Development) to use the Cygwin compiler/debugger. This is my first structured experience with C++, and I'm running into a slight issue. When I attempt to run a program within NetBeans (F11 or the Green Triangle) the project builds ...

Undefined reference problem when dynamic library is used

I was reading about static and dynamic libraries. To explore more I created three files 2 .cpp files and 1 .h file demo.h class demo { int a; public: demo(); demo(const demo&); demo& operator=(const demo&); ~demo(); }; demo.cpp #include "demo.h" #include <iostream> demo::demo():a() { std::cout<<"\nInsi...

How do you declare a pointer to a function that returns a pointer to an array of int values in C / C++?

Is this correct? int (*(*ptr)())[]; I know this is trivial, but I was looking at an old test about these kind of constructs, and this particular combination wasn't on the test and it's really driving me crazy; I just have to make sure. Is there a clear and solid understandable rule to these kind of declarations? (ie: pointer to... arr...

Is it possible to force an access violation when a specific address is accessed?

We have an array that is oversized for alignment purposes, such that off by one errors are not caught by the usual mechanisms. Is it possible to protect a small, arbitrary region (16 bytes at the beginning and end of an array) in Windows, such that it causes an access violation? Language is C++. ...

std::fstream will not open current process's file, but open() will?

I am attempting to open the current process's executable file for read-write operations (I have additional data attached to the executable), however std::fstream will not open the file in ios::in | ios::out | ios::binary mode, even though open() will (with O_RDWR flag set). Does anyone know why std::fstream will not open the file, while...

Game engine development

I am going to be re-creating a game engine I created awhile back. This time I want to do it right, so I did some research into design patterns and tried to put pieces together to accomplish my goal. The idea of the game engine is simplicity, but at the same time I don't want to sacrifice usability. Here is a blueprint of what I am think...

Receiving GLU_TESS_ERROR_5 from GLU Tesselator

Here is my issue. I'm tesselating complex, self intersection, multicontour polygons with hundreds of verticies. The GLU Tesselator crashes with null pointer 0x0000000 issue. It never ever crashes when I do not make self intersecting polygons. If it does not intersect, it will never crash no matter what the circumstances. I check for NULL...

why is this function failing?

am trying to understand windows hooks by writing a few keyboard hooks. i have a function, bool WriteToFile(WPARAM keyCode, char * fileName) { ofstream fout("filename"); if(fout.is_open()) { if(keyCode>=0x030 && keyCode<0x039) fout<< (keyCode - 0x030); fout.close(); return true; } ...

What happens when i throw an exception in c++ destructor ?

Possible Duplicate: throwing exceptions out of a destructor In C++ we should never throw an exception in the destructor . Does this code works as intended ? struct a { ~a( ) { } }; struct b : public a { ~b( ) { throw 1; }; }; bool c( ) { a* d=new b; try { delete d; ...

How to use a C++ string in a structure when malloc()-ing the same structure?

I wrote the following example program but it crashes with segfault. The problem seems to be with using malloc and std::strings in the structure. #include <iostream> #include <string> #include <cstdlib> struct example { std::string data; }; int main() { example *ex = (example *)malloc(sizeof(*ex)); ex->data = "hello world"; std::c...

How do I create an elegant for_each() in C++ inside a member function where the operating function is another member function in the same class?

Here is what I'm trying to do: //ImageCache.h: #include <map> #include <SDL.h> typedef pair<const wchar_t*, SDL_Surface*> ImageNameAndSurface; class ImageCache { // Functions public: ImageCache(); ~ImageCache(); SDL_Surface* getImage(const wchar_t* imageFilename); // Variables private: map<const ...

code to calculate time in nanoseconds

i have following code #include <iostream> #include <time.h> #include <stdlib.h> #include <stdio.h> int main(){ //nanoseconds int x,y; x=6700; y=10000; int z=0; clock_t t =clock(); while (y!=0){ z+=x<<2; x=x>>2; y>>=2; } t=clock()-t; t=1000*t/CLOCKS_PER_TICK; printf(...

CRC32 (Cyclic Redundancy Checksum) to string

Hi, If I have CRC32 (Cyclic Redundancy Checksum) then how can I get string from this. ...

Avira Antivirus detects the listen function as backdoor model

The function listen( ListenSocket, SOMAXCONN ) is detected by avira antivirus as a backdoor model. How can I write small client/server applications without a listen function? Is there a way to do it? ...

hybrid algorithms in energy efficiency for wireless lan

Hi friends I looking for hybrid algorithms in energy efficiency for wireless lan. I look an example of this code in c ,cpp, matlab or any other language that I can easily use it. I already write RSA and ECC algoritm ,but I dont have any idea about how to implement hybrid algoritm,would you help me in this problem? RSA = Rivest Shamir ...

OpenSSL + c++: How do you verify a public key was issued by your private CA?

I have created a CA cert, and used it to issue a public key. At a date in the future, I need to verify that the certificate loaded was issued by my CA. How do I do that with the OpenSSL API (c++)? ...

Rename Pdf from Pdf title

Dear all: I want to organize my pdf file downloaded from the internet. It is clear that many of them are ill-named. I want to extract the real title from the file. Here many of them are generated from Latex and I think from the compiled pdf we can find the \title{} keyword or something like that. I want then use this to rename the file. ...