c++

Why does C++ define the norm as the euclidean norm squared

This may sound like a bit of a rhetorical question, but I ask it here for two reasons: It took me a while to figure out what C++ std::norm() was doing differently from Matlab/Octave, so others may stumble upon it here. I find it odd to define the norm() function as being something different (though closely related) to what is generally...

Is there a way to delimit strings in C++ like PHP's Heredoc Syntax?

This has been driving me crazy. I know in C++ and in PHP you can fill a string or a file with hard coded text. If I remember correctly this is how it is supposed to look: var <<< DELIMITER Menu for program X 1.Add two numbers 2.Substract two numbers 3.Multiply two numbers Please pick an option from (0-3); DELIMITER Th...

Deallocation of an array of objects?

I'm having some issues deallocating arrays of a class I have. Below is the Class, a simplified implementation and my code I have tried to use to close it. Characters class #include <cstdlib> class Character { private: bool human; int Xposition; // the character's postion on the board. int Yposition; // the cha...

Easiest implement pattern 1 writer - multiple readers with boost library

Hi! I develop a module with multiple threads and one Cache in std::map. Some times I need to update cache. In that time all readers must wait, while I do update map. How can I do this synchronization with boost library? P.S.: some time ago in Boost was read_write_mutex. But in current releases of Boost it missed. ...

lock free arena allocator implementation - correct?

for a simple pointer-increment allocator (do they have an official name?) I am looking for a lock-free algorithm. It seems trivial, but I'd like to get soem feedback whether my implementaiton is correct. not threadsafe implementation: byte * head; // current head of remaining buffer byte * end; // end of remaining buffer void * All...

seg faults due to multithreading (using boost libraries)

We have a program that uses both boost's matrix and and sparse matrix libraries and we are attempting to integrate boost threads. However, when we move from a single-threaded to multi-threaded application we are getting segmentation faults that do not occur in the single-thread case. We've debugged using gdb (in Eclipse) and I've found...

Best Language for a Mandelbrot Zoom?

Hi, I've been pretty interested in coding a Mandelbrot Set zoom and have already done it twice. However there were problems with each one. The first time I thought it'd be cool to do it in javascript... but that was so damn slow. Then I did it in C++, which worked great until you zoomed so far that the units on the graph got to the sma...

Telnet Library for C++

Is there a telnet library that I can use with c++ (for Linux)? I would like to telnet to a remote device, run some commands, parse the o/p and present the results. ...

Qt UI for existing C++ project

I have already written a C++ program and I would like to write a GUI for it. I realize Qt is a wonderful tool, however, Qt has it's own classes, which make me quite confused. eg: instead of String, Qt has a class named QString.. I am wondering if I can mix C++ code and Qt code in C++? ...

MSVC's _M_X64 Predefined Macro Clarification

The documentation for MSVC's Predefined Macros state "_M_X64 [is] Defined for x64 processors." What does that mean, exactly? Will it be defined: When I'm building for x64 processors, or When I'm building with x64 processors? Specifically, I'm looking for a compiler switch for the former case, not the latter. Will _M_X64 suffice for t...

Loader lock (regsvr32 R6033 error) with managed C++ dll

I have a C++ dll which implements several COM interfaces, that I'm trying to migrate to managed C++. I set the /clr compiler flag and changed the Runtime Library property from /MT to /MD to avoid the conflict between these two flags, but that's all I've changed. When it attempts to register the dll during the build process, I get the f...

Why on earth would anyone use set instead of unordered_set?

Please, excuse my ignorance about this subject :) C++0x is introducing unordered_set which is available in boost and many other places. What I understand is that unordered_set is hash table with O(1) lookup complexity. On the other hand, set is nothing but a tree with log(n) lookup complexity. Why on earth would anyone use set instead o...

How to get a C method to accept UIImage parameter?

I am trying to do some Image processing on a UIImage using some EAGLView code from the GLImageProcessing sample from Apple. The sample code is configured to perform processing to a pre-installed image (Image.png). I am trying to modify the code so that it will accept a UIImage (or at least CGImage data) of my choice and process that inst...

Why does the C++ ofstream write() method modify my raw data?

I have a jpeg image in a char[] buffer in memory, all I need to do is write it out to disk exactly as is. Right now I'm doing this ofstream ofs; ofs.open(filename); ofs.write(buffer, bufferLen); ofs.close(); but the image doesn't come out right, it looks garbled with random black and white stripes everywhere. After comparing the imag...

In C++ how to return index of an array if user entered matches entered array ?

Hi All, I wanted to know how can we get the index of the array if the user entered array matches the input array ? For example: Input Array = [1,2,3,4] and user entered Array = [2,3] than I should get output as index where both array matches is 1. Guidance would be highly appreciated. ...

Static local in class member function survives class reallocation?

class Foo { public: void bar(); }; void Foo::bar() { static int n = 0; printf("%d\n", n++); } int main(int argc, char **argv) { Foo *f = new Foo(); f->bar(); delete f; f = new Foo(); f->bar(); delete f; return 0; } Does n reset to 0 after delete'ing and new'ing the class over again? Or is n e...

problems using STL std::transform from cygwin g++

I am running g++(gcc version 3.4.4) on cygwin. I can't get this small snippet of code to compile. I included the appropriate headers. int main(){ std::string temp("asgfsgfafgwwffw"); std::transform(temp.begin(), temp.end(), temp.begin(), std::toupper); std::cout <<...

Error while inserting pointer to a vector

Hi I have the following CPP code snippet and the associated error message: Code snippet struct node{ char charVal; bool childNode; struct node *leftChild; struct node *rightChild; }; vector<std::pair<int,struct node*> > nodeCountList; struct node *nodePtr = new struct node; nodeCountList.pus...

Have you Guys Heard of C++ Server Pages?

I have been looking for a ways to maximize speed in my web application. Came across an interesting application called CSP. Have you guys ever heard of them? They claim that you can program web application in c++. Is it worth it? http://www.micronovae.com/CSP.html ...

Pointer comparison

Does pointers in C and C++ support comparison operators (>, <, etc.) in standard? I want to compare array positions to be precise. ...