c++

MakeFile Error for running a cpp file in ssh

CC=g++ CFLAGS=-O0 TARGET=./problem2_cpp OUTFILE=../output/cpp.txt $(TARGET): problem2.o $(CC) $(CFLAGS) -o $(TARGET) problem2.o problem2.o: problem2.cpp $(CC) $(CFLAGS) -c problem2.cpp clean: rm -f *.o $(TARGET) $(OUTFILE) run: $(TARGET) $(TARGET) <$(INFILE) >$(OUTFILE) I am a rather simple makefile to compile,run a cpp, and out...

Code review: How could I simplify this simple method?

I have the following simple method for doing a complete search of a binary tree. I can definitely tell it can be simplified, but it's not coming to me. bool Node::lookup(int d) { if (data==d) { return true; } else { if (left != NULL && right != NULL) { return left->lookup(d) && ri...

How can I find the depth of a recursive function in C++

How can I find the current depth inside a recursive function in C++ without passing in the previous level? i.e. is it possible to know how many times the function was called without using a parameter to keep track of the level and passing that number in as a parameter each time the function is called? For example my recursive function l...

C++ Executable Freezes at Runtime

I wrote a simple console program for the use of testing some key classes in a library I'm building. Now, the code builds correctly with no errors. But, after executing the code, I found that the application stops working after calling the Index method at a certain point in the code. I tried debugging a few different ways to get more info...

C++ decision tree with pruning

Hello. Can you recommend me a good decision tree C++ class with support for continous features and pruning(its very important)? Im writing a simple classifier(two classes) using 9 features. I've been using Waffles recently, but looks like tree is overfitting so i get Precision around 82% but Recall is around 51% which is inacceptable. Wa...

Sandbox Virtual Machine for an Application (C++ vs. C#)

I'd like to write a sandbox virtual machine for executing a compiled program. How do you think: which of these two languages would be better to use if we consider performance? Or maybe you suggest another one? ...

Is it necessary to delete elements as an array shrinks?

Hi I'm a student writing a method that removes zeros from the end of an array of ints, in c++. The array is in a struct, and the struct also has an int that keeps track of the length of the array. The method examines each element starting from the last, until it encounters the first non-zero element, and marks that one as the "last ele...

getline function reading random characters not in the file; two random characters are read along with the data in the notepad keyword.txt

#include "keywords.h" #include <iostream> #include <fstream> #include "llist.h" #include <string> using namespace std; //default constructor List<string> L; keywords::keywords(){ } void keywords::open_file(string filename) { input.open(filename.c_str()); } void keywords::close_file(){ input.close(); } void keywords::load() { ...

Draw to HDC with user allocated memory

I have an windowless IViewObject object. I want to call its Draw function to render into Opengl PBO memory (alternatively OleDraw is simpler). Right now i first create an HBITMAP using CreateDIBSection (which allocates its own memory) and then copy from this into my PBO memory. However, I'd like to avoid this extra copy. I believe this...

Trying to make an array of DirectX vertex with out knowing until run time what type they will be

Bit of background for those who don't know DirectX. A vertex is not just an XYZ position, it can have other data in it as well. DirectX uses a system known as Flexible Vertex Format, FVF, to let you define what format you want your vertexs to be in. You define these by passing a number to DirectX that use bitwise or to build it up, eg (D...

C++ casting of templated class

Hello, I have a question about templates. I would like to have a templated class that contains, say, an array of either float's or double's. I can write a clone() function that duplicates it. No problem. However, I would like to have another function called cast() that does a translation back and forth between double and float. This ha...

Boost regex incorrect syntax

Hi, I am using the Boost library under c++ to parse a load of text. I seem to be having a problem with this string text text text Seat 6: player_name (11,111) text text text I am trying to match on the middle bit, the seat number can be anything between 1 and 9, the player_name can be any character a-zA-Z and include numbers *_. an...

C++ basic qt question

Hello! Does someone know a fast way to add the ability to rotate and move a 3D model using Qt? Obviously, I have to make changes to the world matrix based on the mouse and keyboard movements, and hence I should somehow handle the appropriate mouseEvents and keyboardEvens. For a 3d camera this seems a bit tricky and although I could im...

Undefined reference to member functions

I had just thought I resolved a problem, but it seemed another one cropped up--or at least the same problem in another form. Now when I try to rebuild everything as suggested in the answer to that question, all Qt Creator shows in build issues is a one line collect2: ld returned 1 exit status Here's some of the compile output that I thi...

Dividing 3D points with xyz coordinates in to 10 domains based on spatial proximity

I have a set of xyz coordinates for points distributed on a arbitrary 3D surface.(about 50000) I need to group these points in to 10 domains each containing approximately 1/10th of data points according to spatial proximity. Basically 10 surface patches on the surface. Thanks. ...

faster than binary search for ordered list

is there an algorithm that is faster than binary search, for searching in sorted values of array? in my case, I have a sorted values (could be any type values) in an A array, I need to return n if the value I was looking is in range of A[n] and A[n+1] ...

How do I catch a C++ exception?

In my C++ app, I'm making a call to System() that crashes the app sometimes (it's a service). I'd like to catch the exception that is thrown and log it. I don't know what exactly to catch, though, and I can't even do a blanket catch: try { system(myCommand); } catch (...) { Log("Error!"); // this is a custom log method } That do...

is setlocale thread-safe function?

hi, i need to change locale in the thread to parse double with strtod() correctly, i'm using setlocale() for this (C++). is it thread safe? UPD: another problem. when i invoke setlocale() in main function it doesn't effect in other routines deeper. why??? there are a lot of code, so it's problematic to write the chunk. ...

Odd error message when instantiating a template class

Hi all, I am getting an error I do not understand. There was even a similar question asked on SO that I found, but the fix given is already in my code. I am getting an error in this line: ForestNode<NODETYPE> foo = new ForestNode<NODETYPE> ForestNode(bar); that reads : \project 4\forest.h|85|error: expected ',' or ';' before 'Fores...

Timeout based concurrent queue in C++

I am trying to develop a concurrent queue using POSIX threads + C++ with the following semantics: Some threads may call push(item, timeout) and if the addition of the element does not happen by time timeout it must be rejected. Some threads may call pop(item, timeout) and again if deletion of the element does not happen by time timeou...