c++

Reverse engineer C++ DLL

I have a small utility that was originally written in VS2005. I need to make a small change, but the source code for one of the dlls has been lost somewhere. Is there a free or reasonably priced tool to reverse engineer the dll back to C++ code. ...

C++ vim IDE. Things you'd need from it.

Hi guys. I was going to create the C++ IDE Vim extendable plugin. It is not a problem to make one which will satisfy my own needs. This plugin was going to work with workspaces, projects and its dependencies. This is for unix like system with gcc as c++ compiler. So my question is what is the most important things you'd need from an ID...

Compiling a C++ .lib with only header files?

I'm compiling a C++ static library and as all the classes are templated, the class definitions and implementations are all in header files. As a result, it seems (under visual studio 2005) that I need to create a .cpp file which includes all the other header files in order for it to compile correctly into the library. Why is this? ...

Handcode GUI or use gui-designer tool

I would like to hear some opinions on hand coding your GUIs as one typically do when using Java or Qt with C++, vs using a gui-designer tool? Examples of GUI designer tools would be MFC GUI-designer, Qt designer, Interface Builder (Apple). I used to be a fan of hand coding but from recent experience I have switched. The problem I have s...

Accessing struct members directly

I have a testing struct definition as follows: struct test{ int a, b, c; bool d, e; int f; long g, h; }; And somewhere I use it this way: test* t = new test; // create the testing struct int* ptr = (int*) t; ptr[2] = 15; // directly manipulate the third word cout << t->c; // look if it really affect...

How does one write the hex values of a char in ASCII to a text file?

Here is what I currently have so far: void WriteHexToFile( std::ofstream &stream, void *ptr, int buflen, char *prefix ) { unsigned char *buf = (unsigned char*)ptr; for( int i = 0; i < buflen; ++i ) { if( i % 16 == 0 ) { stream << prefix; } stream << buf[i] << ' '; } } I've tried doing stream.hex, str...

Defining a class within a namespace

Is there a more succinct way to define a class in a namespace than this: namespace ns { class A {}; } I was hoping something like class ns::A {}; would work, but alas not. ...

Which floating-point image format should I use ?

In the past I've saved RGB images (generated from physical simulations) as 8-bits/channel PPM or PNG or JPEG. Now I want to preserve the dynamic range of the simulation output, which means saving a floating point image and then treating conversion to 8-bits/channel as a post-processing step (so I can tweak the conversion to 8-bit withou...

32 bit Linux clock() overflow

I need to measure, in C++ on Linux (and other Unix-like systems), the CPU (not wall clock) time taken by a long computation, so I'm using clock(). Problem: on 32 bit systems, this wraps around after about 2000 or 4000 seconds. What's the recommended workaround for this? ...

Problems with string

Hi. Im working with a cstring function that is supposed to compare the values of two strings, MyString and m2. I have #include so its definitely not that. these are my errors. (74) : error C2275: 'MyString' : illegal use of this type as an expression (74) : error C2660: 'MyString::length' : function does not take 1 arguments (76) : err...

How do I read / write gzipped files?

How do I read / write gzipped files in C++? The iostream wrapper classes here look good, and here is a simple usage example: gz::igzstream in(filename); std::string line; while(std::getline(in, line)){ std::cout << line << std::endl; } But I wasn't able to actually link it (although I have a /usr/lib/libz.a). A simple g++ test-gzs...

How to reuse an ostringstream?

I'd like to clear out and reuse an ostringstream (and the underlying buffer) so that my app doesn't have to do as many allocations. How do I reset the object to its initial state? ...

How can I build different versions of a project using the Jam make tool?

I have a C++ project that compiles to different versions, including release, debug, shared library, and executable, with different compiler flags for each. I am trying out Jam as an alternative to Make, because it looks like a simpler system. Is Jam capable of this? The main problem is that it always places the .o files into the same f...

What would it take for people to move away from C++?

Even most people who like C++ admit that it has tons of warts not related to its niche as a systems/performance programming language. These include its antiquated module management system (header files), requirement for forward declarations, syntax quirks that make its grammar undecidable (such as <> angle brackets for template declarati...

Algorithm to return the maximum possible sum of subsequences in a sequence

int maxSumRec(const vector<int> &a, int left, int right){ if (left == right){ if (a[left] > 0){ return a[left]; } else return 0; } int center = (left + right)/2; int maxLeftSum = maxSumRec(a, left, center); int maxRightSum = maxSumRec(a, center+1, right); int lef...

Passing a pointer to process spawned with exec()

I would like to pass a pointer (I am putting a file with data in memory with mmap) to processes spawned using fork + exec, but I am stuck on how to pass a pointer to the exec() spawned process? UPDATE1: Thanks for your inputs, I do use shared memory creating it with mmap with MAP_INHERIT flag: Each mapped file and shared memory region...

static_cast with boost::shared_ptr?

What is the equivalent of a static_cast with boost::shared_ptr? In other words, how do I have to rewrite the following Base* b = new Base(); Derived* d = static_cast<Derived*>(b); when using shared_ptr? boost::shared_ptr<Base> b(new Base()); boost::shared_ptr<Derived> d = ??? ...

C++ class best practice

I'd like to know some best practice when designing c++ classes. To put it in context, I have a c++ class named Vec3. class Vec3{ private: float elements[3]; public: Vec3(Vec3 v1){...} Vec3(int x, int y, int z){...} Vec3 add(Vec3 v1){...} Vec3 add(int x, int y, int z){...} ... Vec3 multiply(Vec3 v1){...} ...

Compact way to extract parts of strings (FASTA header)

Hi, Given the following string: string Header =">day11:1:356617"; How do you extract everything except ">", yielding only: day11:1:356617 I could do standard loop over the string character and keep only other than ">". string nStr =""; for (int i=0; i < Header.size(); i++) { if (Header[i] != ">") { nStr = nStr + He...

How do you read a word in from a file in C++?

So I was feeling bored and decided I wanted to make a hangman game. I did an assignment like this back in high school when I first took C++. But this was before I even too geometry, so unfortunately I didn't do well in any way shape or form in it, and after the semester I trashed everything in a fit of rage. I'm looking to make a txt ...