c++

Simplify config-file-driven factory

Hej! Caution this is a long post -- if you are easily annoyed better skip it. ;-) The Project I am working on currently is about reading voltage measurements of different sensors and calculating the respective physical value. There are a number of channels each of which can have a different sensor attached. Basicly the kind of sensor i...

Writing to user documents folder C++

Hi everyone, I'm trying to write some info to the user's documents folder (eg. C:\Documents and Settings\[userName]), but I can't seem to find out how to grab the path programmatically. Is there any way to do this? C++, not using .NET. Thanks! ...

What should happen to the negation of a size_t (i.e. `-sizeof(struct foo)`))?

I'm dealing with some code at work that includes an expression of the form -(sizeof(struct foo)) i.e. the negation of a size_t, and I'm unclear on what the C and C++ standards require of compilers when they see this. Specifically, from looking around here and elsewhere, sizeof returns an unsigned integral value of type size_t. I can'...

Template's member typedef use in parameter undeclared identifier in VS but not GCC

I'm looking at some codes which makes heavy uses of templates. It compiles fine on GCC, but not on VS (tested on 2003 - 2010 beta 1), where it fails during syntax analysis. Unfortunately I don't know enough of the code structure to be able reduce the problem and reproduce it in only a few lines, so I can only guess at the cause. I'm hopi...

Error passing 2D char* array into a function.

I'm trying to pass a 2D array of char* into a function. I am getting this error: "cannot convert 'char* (*)[2]' to 'char***' for argument '1' to 'int foo(char***)'" Code: int foo(char*** hi) { ... } int main() { char* bar[10][10]; return foo(bar); } ...

Boost regex not working as expected in my code

I just started using Boost::regex today and am quite a novice in Regular Expressions too. I have been using "The Regulator" and Expresso to test my regex and seem satisfied with what I see there, but transferring that regex to boost, does not seem to do what I want it to do. Any pointers to help me a solution would be most welcome. As a ...

C++: Looking for a concise solution to replace a set of characters in a std::string with a specific character

Suppose I have the following: std::string some_string = "2009-06-27 17:44:59.027"; The question is: Give code that will replace all instances of "-" and ":" in some_string with a space i.e. " " I'm looking for a simple one liner (if at all possible) Boost can be used. ...

tutorials about WinAPI unicode?

Hi, I'm wondering if you guys are aware of any article of some sort that shows how to make code fully unicode? Reason I ask is because I'm dealing with winapi right now and it seems that everything's supposed to be unicode like L"blabla" .. Functions that I've encountered won't work properly by simply using the standard string for examp...

Globbing in C++/C, on Windows

Is there a smooth way to glob in C or C++ in Windows? E.g., myprogram.exe *.txt sends my program an ARGV list that has...ARGV[1]=*.txt in it. I would like to be able to have a function (let's call it readglob) that takes a string and returns a vector of strings, each containing a filename. This way, if I have files a.txt b.txt c.txt i...

Using Boost Graph Library: property_map in boost::mutable_queue

...

Passing a constant array to a function in C/C++

If I have a prototype that looks like this: function(float,float,float,float) I can pass values like this: function(1,2,3,4); So if my prototype is this: function(float*); Is there any way I can achieve something like this? function( {1,2,3,4} ); Just looking for a lazy way to do this without creating a temporary variable, bu...

Resources to learn C++ itself, not the basics of programming?

I'm something of a new, reluctant convert to C++ from a Pascal, Ruby, and PHP background. I haven't worked with Pascal since a few months of torture with "Delphi Turbo;" since then I've practically been eating and sleeping Ruby and PHP. I'm already well acquainted with object oriented programming and many various subjects. My main troub...

How to verify if a window of another program is minimized?

How can I do this? I've tried IsWindowVisible() but that doesn't seem to do the job. ...

Is there a way to verify that the current window of another program is totally visible?

Is there any function, or I'll have to iterate through all windows that are in front of mine and detect if they overlap my window? Thanks ...

Unusual Speed Difference between Python and C++

I recently wrote a short algorithm to calculate happy numbers in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm I knew of from python to c++. Surprisingly, the c++ version runs significantly...

delete[] and memory leaks

Hi, I am wondering about the delete[] operator in C++. (I am using Visual Studio 2005). I have an unmanaged DLL that is being called by a managed DLL. When I close this program after performing a few tasks while debugging, I am getting many (thousands?) of memory leaks, mostly 24 bytes - 44 bytes in size.. I suspect it might be due to a...

Qt Widget being resized twice upon initialization?

My "EditorView" (a QGLWidget) is being resized twice when it's created. It starts at say 846x630, then shrinks to 846x607 (losing 23 pixels in height). Created like this: EditorWindow::EditorWindow() { Q_INIT_RESOURCE(icons); readSettings(); setWindowTitle("Q2D Map Editor"); createActions(); createMenus(); cre...

Implementing Skip List in C++

[SOLVED] So I decided to try and create a sorted doubly linked skip list... I'm pretty sure I have a good grasp of how it works. When you insert x the program searches the base list for the appropriate place to put x (since it is sorted), (conceptually) flips a coin, and if the "coin" lands on a then that element is added to the list a...

Have you used boost::tribool in real work?

tribool strikes me as one of the oddest corners of Boost. I see how it has some conveniences compared to using an enum but an enum can also be easily expanded represent more than 3 states. In what real world ways have you put tribool to use? ...

nanoseconds to milliseconds - fast division by 1000000

Hi, I'm wanting to convert the output from gethrtime to milliseconds. The obvious way to do this is to divide by 1000000. However, I'm doing this quite often and wonder if it could become a bottleneck. Is there an optimized divide operation when dealing with numbers like 1000000? Note: Any code must be portable. I'm using gcc and thi...