c++

C++: A way to declare a variable (or more than one) in an if statement that separates out the variable definition and the test?

One can do this: case WM_COMMAND: if (WORD wNotifyCode = HIWORD(wparam)) { ... } And one can do this: case WM_COMMAND: { WORD wNotifyCode = HIWORD(wparam); if (wNotifyCode > 1) { ... } } But one cannot do: case WM_COMMAND: if ((WORD wNotifyCode = HIWORD(wparam)) > 1) { ... } Using a for statement here I think is mi...

How to use C++ operators within python using boost::python (pyopencv)

I'm using the pyopencv bindings. This python lib uses boost::python to connect to OopenCV. Now I'm trying to use the SURF class but don't know how to handle the class operator in my python code. The C++ class is defined as: void SURF::operator()(const Mat& img, const Mat& mask, vector<KeyPoint>& keypoints) const {...}...

Linking different libraries for Debug and Release builds in Cmake on windows?

So I've got a library I'm compiling and I need to link different third party things in depending on if it's the debug or release build (specifically the release or debug versions of those libraries). Is there an easy way to do this in Cmake? Edit: I should note I'm using visual studio ...

Any gotchas in copy ctor and assignment operator having slightly different semantics?

Please look at the following code and tell me if it's going to cause problems in the future, and if yes, how to avoid them. class Note { int id; std::string text; public: // ... some ctors here... Note(const Note& other) : id(other.id), text(other.text) {} void operator=(const Note& other) // returns void: no chaining ...

GLUT_SINGLE displays a black screen

It took me >1 day and I still haven't figured out why. I'm using Ubuntu 9.10, trying to make a simple OpenGL to work in c++. whenever I used GLUT_SINGLE parameter, it gives me a full black screen. I had to click mouse randomly on that screen in order to get out. This is so much annoying. Possibly a bug. Can anybody help? Here is the ...

How to properly do threading in C++?

I have a rather large, dynamic sparse matrix object class to write, and I want to make the following happen: one thread to handle placing elements into the matrix, and one to handle reading from the matrix. The only time when these two would conflict would be when they would both want to access the same row/column at the same time. As ...

CoInitialize Failed

We had multi-threaded application. Each thread has to invoke with CoIntialize when it is iniatialized as we use some C++ COM object for our DB operation. The application is working fine for longer time in the production env. But suddently the CoIntialize() API in thread init function failed with below error ThreadInit; HRESULT: 80070008 ...

http proxy javascript injection

I have a simple proxy source in C++. I'm trying to modify it to inject some html content into specific pages. I'v managed to get it working but whenever I inject something, part of the original html gets corrupted. I know for a fact that it's not my string handling functions because I have it printing out the result before sending and it...

Search a large file for data in C/C++

Hi all, I have a log file which has a format of this kind: DATE-TIME ### attribute1 ### attribute2 ###attribute3 I have to search this log file for a input attribute(entered from command line) and output the lines that match the entered attribute. A naive approach may be something like this: scan the entire file line by line searc...

How to determin if a SystemTime value is in UTC

Is there a way to determine the timezone of a DATE data type that has been converted to a SystemTime value? Let say a C# file using the COM lib set the value below: someComInterface.someDateAttribute = new DateTime(somedate).ToUniversalTime(); In the COM library I want to do something like this if(VariantTimeToSystemTime(DATE, &syst...

Manual alternative to message map?

I am trying to create a GUI to display information read from a file. So I will need some number of pushbuttons, text fields, and radio buttons - but I won't know how many I need until run-time. I am using Visual Studio 6.0. My toolset is fairly non-negotiable, so please refrain from suggesting Java, or any C++ toolkit that does not co...

Swap method with const members

Hi everyone! I want to implement a Swap() method for my class (let's call it A) to make copy-and-swap operator=(). As far as I know, swap method should be implemented by swapping all members of the class, for example: class A { public: void swap(A& rhv) { std::swap(x, rhv.x); std::swap(y, rhv.y); std:...

Creating a simple program in C++ for windows. How to build GUI

For a school project, we need to create a fairly simple app using C++ and .NET framework. I only know C++, but we need to produce a working executable file for the project. The prof said we can use WYSIWYG editors for the GUI, but i can't seem to find one in Visual C++. I wanted to code with Visual C++ since i want to learn about Visual ...

compile SQLite amalgamation for Windows Mobile device

How can I compile the SQLite amalgamation for Windows Mobile device? Then I want to use in a console to run some commands. I've created an empty VS project in C/C++ for Smart Device, then included the existing files into Sources and Headers. When I try to compile I get: Error 1 error LNK2019: unresolved external symbol wmain referen...

How to hide using C\C++ with Show hidden Files and Folder enabled

I would like to know how to programmatically hide a file but making the file or folder still hidden with Show hidden files and folders enabled from the Tools->Folder options of Explorer. I hope I am not confusing anyone and if I might be please just ask. ...

(Text-Based) Games for C++ practice

I'm currently learning C++ and so I thought it would be a good idea trying to (re)program some "common" text-based games. (Thinking of Hunt the Wumpus, Guess a (pseudo) random number generated by the computer,...) However, I can't find any good sources for such tasks. Which text-based games could be "educating" for me to program? Do y...

Conditional CXX_FLAGS using cmake based on compiler?

I've just started using CMake for some personal and school projects, and I've been stumped by a minor issue. Let's say I'm trying to get a C++ program compiling under multiple compilers (g++, cl, and bcc32 in this case). I have different command line switches for each compiler, and what I was attempting to do was to basically make a gnu...

How I do fibonaci sequence under 1000?

#include <iostream> using namespace std; void main() { int i = 0; while (i < 1000) { int TEMP = i * 2; cout << i << endl; TEMP = i; i = i +1; // ??? } return; } I'm so confused?? :( ...

Working with enum-like data in C++

I am updating an old piece of C++ code and am stuck on a design issue and need advice on the best course of action. The code handles geometric data. Currently, the code defines many global constants to handle element types: #define TETRAHEDRON 0 #define HEXAHEDRON 1 Each constant has information associated with it that remains const...

failing to compile a project, missing io.h file

Hello, I fail to compile a C++ project for mobile device with Windows Mobile (Windows CE-based) operating system and Visual C++ compiler from Visual Studio fails with: Error 1 fatal error C1083: Cannot open include file: 'io.h' EDIT I am trying to compile the SQLite amalgamation, the shell.c file includes the call to this io.h bu...