c++

c++ for loop temporary variable use

Hi, Which of the following is better and why? (Particular to c++) a. int i(0), iMax(vec.length());//vec is a container, say std::vector for(;i < iMax; ++i) { //loop body } b. for( int i(0);i < vec.length(); ++i) { //loop body } I have seen advice for (a) because of the call to length function. This is bothering me. Doesn't any...

<operator missing when iterating through c++ map

The following code does not want to compile. See the included error message. Code: #include <map> #include <vector> #include <iostream> class MapHolder { public: std::map<std::vector<std::string>,MapHolder> m_map; void walk_through_map() { std::map<std::vector<std::string>,MapHolder>::iterator it; for(it = m_map.beg...

Windows XP Style: Why do we get dark grey background on static text widgets?

We're writing Windows desktop apps using C++ and Win32. Our dialog boxes have an ugly appearance with "Windows XP style": the background to the static text is grey. Where the dialog box background is also grey, this is not a problem, but inside a tab control, where the background is white, the grey background to the text is very notic...

How do I get the mic volume of all audio cards in Windows XP using C++?

I'm trying to write an application that will get the mic volume of every sound card on a machine. My current code looks like this: for (unsigned int i = 0; i < waveInGetNumDevs(); ++i) { HMIXER hmx; mixerOpen(&hmx, i, 0, 0, MIXER_OBJECTF_WAVEIN); if (hmx == 0) { printf("Unable to open device %d\n", i); continue; } MIXERLINE...

Finding smallest value in an array most efficiently

There are N values in the array, and one of them is the smallest value. How can I find the smallest value most efficiently? ...

How to copy multiple files from server to local hard disk in one http request using C++?

How do you copy a group of files from server machine to local hard disk through a C++ web application in one request? This is kind of downloading bulk files to your local machine from a server. I guess in Java you could do this through ZipInputStream and GZipInputStream. Is it possible to achieve this entirely through server side code? ...

C++ array initialization

Why can’t I initialize a local array with a string ...

How to hash a GUID and a 64-bit timestamp into another GUID

We're working with a proprietary database and have a table whose semantic compound key consists of a 128-bit GUID and a 64-bit timestamp. "Semantic compound key" in a sense that multiple records with the same GUID may occur in the table, as well as multiple records with the same timestamp; however the pair (GUID, timestamp) is unique. As...

Is there a difference between compiling projects in Visual Studio 2008 Pro and the Standard version?

Hi, We are using two different versions of Visual Studio 2008, the Pro and Standard one. I started a Visual C++ MFC project using the Pro version. My teammate wanted to use my project with the standard version, but all he gets are a lot of compile errors about missing afxheaders and stuff like that. We are really helpless and don't kno...

GCC C++ "Hello World" program -> .exe is 500kb big when compiled on Windows. How can I reduce its size?

Hello, I just recently started learning C++ - I am using nuwen's version of MingW on Windows, using NetBeans as an IDE (I have also MSDN AA Version of MSVC 2008, though I don't use it very often). When compiling this simple program: #include <iostream> using namespace std; int dog, cat, bird, fish; void f(int pet) { cout << "pet i...

What is the corresponding function for DeviceIoControl (C++) in C#.net?

DeviceIoControl is used in C++ to communicate with USB device connected to the System. I want to use the same functionality in C#.net, but I can't able find anything similar. ...

Boost and XML (c++)

Hi, Is there any good way (and a simple way too) using boost to read and write xml files? I can't seem to find any simple sample to read xml files using boost? (can you point me some simple sample that use boost for reading and writing xml files) If not boost, is out there any good and simple library to read and write xml files that y...

writing directly to std::string internal buffers

I was looking for a way to stuff some data into a string across a DLL boundary. Because we use different compilers, all our dll interfaces are simple char*. Is there a correct way to pass a pointer into the dll function such that it is able to fill the string buffer directly? string stringToFillIn(100, '\0'); FunctionInDLL( stringToFi...

What does void mean in C, C++, and C#?

Looking to get the fundamentals on where the term VOID comes from and why it would be called void. The intention of the question is to assist someone who has no C experience and is suddenly looking at a C-based codebase. ...

How to buffer output from a .net BackgroundWorker ?

I have a stream of data coming in from an external source which I currently collect in a BackgroundWorker. Each time it gets another chunk of data, it presents that data to a GUI using a ReportProgress() call. I get the impression that the ProgressChanged function is just a synchronisation mechanism though so when my worker thread calls...

Why this code crashes?

For C++ gurus: Can you please elaborate why this code crashes at the places mentioned? I am a bit stumped on this. I guess that it has got something to do with sizeof(int) but I am not so sure. Can anybody explain? class Base { public: virtual void SomeFunction() { printf("test base\n"); } int m_j; }; class Der...

Which is best for a repeating piece of code?

I have a class with two member functions that share a piece of code: void A::First() { firstFunctionEpilogue(); sharedPart(); } void A::Second() { secondFunctionEpilogue(); sharedPart(); } Currently firstFunctionEpilogue(), secondFunctionEpilogue() and sharedPart() are not function calls but just pieces of code, sharedPar...

Do you know which library Firefox 3 uses for the "download completed" info?

It's the window that shows up when you set showAlertOnComplete = true. about:config browser.download.manager.showAlertOnComplete = true I want to add notification messages in my applications and I need to find a good open source library for that task. ...

const char* variable as parameter to function

Hello! I have this constructor implemented in a C++ library(by someone else, not by me): Variables(const char *s) Which I want to use in my own function, useful(). This functions useful(), computes an int which I want to be transmitted as a parameter to the constructor Variables(const char *s). So I am converting the int to a string...

How can I get away from casting in C++?

In C++ you can cast a couple ways, C-style casting or C++ casts. Bjarne Stroustrup and a host of other C++ experts say that a good design should have no casting. Can you help me out here with redesigning the code below to get rid of the cast? void CProgressBar::SetPosition( int nPos ); //unable to change void CSaveDialog::UpdatePosit...