c++

std::mktime and timezone info

I'm trying to convert a time info I reveive as a UTC string to a timestamp using std::mktime in C++. My problem is that in / time.h there is no function to convert to UTC, mktime will only return the timestamp as local time. So I need to figure out the timezone offset and take it into account, but I don't find a plattform independent w...

Print leading zeros with C++ output operator (printf equivalent)?

How can I format my output in C++? In other words, what is the C++ equivalent to the use of printf like this: printf("%05d", zipCode); I know I could just use printf in C++, but I would prefer the output operator <<. Would you just use the following? std::cout << "ZIP code: " << sprintf("%05d", zipCode) << std::endl; ...

What's the difference between a procedural program and an object oriented program?

I'm fairly new to programming but I've been reading some interesting discussions on StackOverflow about various programming approaches. I'm still not 100% clear on what the difference is between procedural programming and object oriented programming. It sounds like object oriented programming still uses procedures (methods) but everythin...

Floating/Embedded QDockWidget in a QWidget (KXmlGuiWindow's CentralWidget designed in QT Designer)

I'm just trying to get into QT (and KDE) program, and have hit a snag trying to add a floatable, draggable QDockWidget to the .ui file (based as a QWidget) that is embedded into my KDE 4 program. This is all from the basic template provided by KDevelop 4, so while I understand what's going on, I just don't know the best way to change it...

Need IPv6 Traffic Generator.

I am looking for the tool to generator IPv6 Traffic. It should allow me to give all its header value manually by me. It would be great if source code is available. Thanks in Advance. ...

Should I put many functions into one file? Or, more or less, one function per file?

I love to organize my code, so ideally I want one class per file or, when I have non-member functions, one function per file. The reasons are: When I read the code I will always know in what file I should find a certain function or class. If it's one class or one non-member function per header file, then I won't include a whole mess ...

Strange assembly from array 0-initialization

Inspired by the question Difference in initalizing and zeroing an array in c/c++ ?, I decided to actually examine the assembly of, in my case, an optimized release build for Windows Mobile Professional (ARM processor, from the Microsoft Optimizing Compiler). What I found was somewhat surprising, and I wonder if someone can shed some ligh...

What is the best way to take screenshots of a Window with C++ in Windows?

What is the best (easiest) way to take a screenshot of an running application with C++ under Windows? ...

C++ for the C# Programmer

I have a good understanding of OO from java and C# and I'm lucky in my engineering courses to have been exposed to the evils of both assembler and C (pointers are my playground :D ). However, I've tried looking into C++ and the thing that gets me is the library code. There are so many nice examples of how to perform the bread and but...

error C2039: 'memchr' : is not a member of '`global namespace''

Hi, It has been quite a while since I am getting this error in the standard <cstring> header file for no apparent reason. A google search brought up many answers but none of them worked. ...

How to setup Google C++ Testing Framework (gtest) on Visual Studio 2005

It is not documented on the web site and people seems having problem setting up the framework. Can someone please show step by step introduction to a sample project setup. ...

Editor core buffer type and syntax highlighting

I've been thinking a lot about making an editor core functionality wise compatible to vim, similar to yzis. The biggest questions are what buffer type to use. Requirement are: possibility to implement fast syntax highlighting, regex on top of it. possibility to implement multiple syntax highlightings in a single file. similar to text...

Is there a way to set the environment path programatically in C++ on Windows?

Is there a way to set the global windows path environment variable programatically (C++)? As far as I can see, putenv sets it only for the current application. Changing directly in the registry (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment) is also an option though I would prefer API methods if there are? ...

Weird behaviour of C++ destructors

#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000, vector<int>(4, -1)); cout << dp.size(); } This tiny program takes a split second to execute when simply run from the command line. But when run in a debugger, it takes over 8 seconds. Pausing the debugger reveals that it is ...

Memory allocation

I have the STRUCT1 Structure declared as below typedef struct struct1 { short int nbr_fe; [size_is(nbr_fe)] STRUCT2 ptr_fe[*]; } STRUCT1; STRUCT2 is also another structure inside STRUCT1 and then I have a pointer declared to it as below typedef [ptr] STRUCT1 * ptr; And I have to allocate a memory to an array of STRUCT1 b...

[C++] Communication between inherited classes.

I have 3 classes in different files: X | ------- | | Y Z I will be creating several objects of inherited classes Y and Z. A specific function in class Z should be executed only if some flag variable is set by class Y. Where should I create this flag variable (which class) and what should be the declaration be like (sta...

How can you parse simple C++ typedef instructions ?

Hi, I'd like to parse simple C++ typedef instructions such as typedef Class NewNameForClass; typedef Class::InsideTypedef NewNameForTypedef; typedef TemplateClass<Arg1,Arg2> AliasForObject; I have written the corresponding grammar that i'd like to see used in parsing. Name <- ('_'|letter)('_'|letter|digit)* Type <- Name Type <- Type...

Why does wgluseFontBitmaps consume too much memory on some computers?

I'm creating a game in OpenGL which loads the entire Arial Unicode MS font when it loads. The program uses on avg. 10 megs of memory on my computer (op sys is WinXP SP2) and runs without problems, but when I move the program to my laptop (with Vista) the wglUseFontBitmaps hangs and allocates memory fluently and never returns. This proble...

Any way to make this relatively simple (nested for memory copy) C++ code more effecient?

I realize this is kind of a goofy question, for lack of a better term. I'm just kind of looking for any outside idea on increasing the efficiency of this code, as it's bogging down the system very badly (it has to perform this function a lot) and I'm running low on ideas. What it's doing it loading two image containers (imgRGB for a fu...

What are the valid values of the expression (uninitialized_bool ? 1 : 2)?

What is the set of valid outputs for the following, according to the standard? bool x; cout << (x ? 1 : 2); edit: unknown(google) has got it. In gcc my code was crashing because of sprite.setFrame(isPressed ? 0 : 1) with the conditional returning 28! ...