c++

boost::format question

Consider the following : #include <vector> #include <string> #include <iostream> #include <boost/format.hpp> #include <boost/assign.hpp> #include <boost/assign/list_of.hpp> #include <boost/assign/std/vector.hpp> using namespace std; typedef unsigned char byte; typedef vector<byte> byte_array; const byte_array bytes = list_of(0x05)(0...

Adding elements to an STL Map in a constructors Initialization List?

I was wondering if this was possible, and if so how I'd go about doing so. If it's not possible I'll just have to add the elements during the constructor body. Ideally I would like the map immutable after construction. What I'm trying to achieve is adding two pairs to the map that are created from constructor parameters. ...

URI Escape C++ wstring

I am looking for a good way to do a URI Escape in C++ that would be reasonable for a cross platform project. I would like a function that would take a string like this: L"jiayou加油" And return: L"jiayou%E5%8A%A0%E6%B2%B9" I looked at using some thing like this, with minor modifacations to use wchar_t. However that would require con...

How to synchronize and combine results from multiple threads in C++?

I have a data feed continuously feeding data packet in. There are 5 threads(A, B, C, D, E) processing the data packages. Note the 5 threads have totally different speed and they generate 5 different features(each thread generate 1 feature) for every incoming data package. The 5 threads are at different pace: when A has finished analyzin...

Who deletes the memory allocated during a "new" operation which has exception in constructor

I really can't believe I couldn't find a clear answer to this... How do you free the memory allocated after a C++ class constructor throws an exception, in the case where it's initialised using the "new" operator. E.g.: class Blah { public: Blah() { throw "oops"; } }; void main() { Blah* b = NULL; try { b = new Bla...

Out of four std::vector objects select the one with the most elements

I have four std::vector containers that all might (or might not) contain elements. I want to determine which of them has the most elements and use it subsequently. I tried to create a std::map with their respective sizes as keys and references to those containers as values. Then I applied std::max on the size() of each vector to figure ...

What are the major issues to look for when moving an application built in Qt for a Symbian platform to a Windows Mobile platform?

I have an existing application created using Qt for the Symbian operating system and I want to port it to Windows Mobile devices. I'm expecting some presentation differences. What additional things should I look out for? ...

How to use array optimization in boost serialization

I have to serialize an object that contains a std::vector that can contain thousand of members, with that vector sizes the serialization doesn't scale well. According with the documentation, Boost provides a wrapper class array that wraps the vector for optimizations but it generates the same xml output. Diving in boost code, i've found...

DirectSound: how to change the input volume of a microphone?

Hi, I have some questions about Directsound and windows mixers. My goal is to enumerate all microphones and be able to change the input volume of each one. I think i'm not far from the solution, but I don't find what is wrong in my code. Here is what I have done: - I enumerate all input devices and get a GUID for each one - I use a meth...

Reading an std::ifstream to a vector of lines

How would I go about reading in a file where each line is a single number, then outputing that number into a vector of lines? eg: file.txt contains: 314 159 265 123 456 I have tried this implementation: vector<int> ifstream_lines(ifstream& fs) { vector<int> out; int temp; getline(fs,temp); while (!fs.eof()) { ...

intersect two maps using only keys as a comparator

Hi all, I have two maps and I would like to get map which is intersection of two using only key as a comparator and in the same time do simple math operation on values of common elements such as +/- for example : map<int, double> m1,m2; m1[1] = 1.1; m1[2] = 2.2 m2[2] = 0.1; m2[4] = 3.3; after intersection i will get m3 which will h...

High-performance Math library for .NET /C# and Java

We currently have a high-performance scientific application written in C++ that makes use of Intel Math Kernel Library. We are considering writing a benchmark application written in Java and .NET/C# to compare the performance difference. To do that, we also need a good (commercial is preferred) math library for both. Does anyone know of...

Queue + Stack C++

Hello, How do u push Items to the front of the array, ( like a stack ) without starting at MAXSIZE-1? I've been trying to use the modulus operator to do so.. bool quack::pushFront(const int nPushFront) { if ( count == maxSize ) // indicates a full array { return false; } else if ( count == 0 ) { ...

How do I set a background color for the whole window of a Qt application?

Does anyone know if/how one would be able to set a background color for the whole window of a Qt application? So far I am using stylesheets but can only figure out how to assign a background color to a widget such as QGroupBox or QPushButton. Basically, if I want a black background how would I make it seamless without any borders of the ...

Where are sample Select2Perform test questions?

Has anyone taken a Select2Perform test? I know one can take a sample Brainbench C++ test online for free, but can anyone take a sample Select2Perform C++ test online to know the kind of questions? I need to take one for a job opportunity. Joe ...

C++ const void* conversion

I'm trying to pass three parameters to my write() function: write(fd, "C,1,1\r\n", 7); This works fine. But I would like to take a parameter and pass it to the command portion to make it dynamic: write(fd, N, 4); I'm not familiar with c++ types, but it keeps asking for a type of "const void*" I've been able to convert my variable, ...

C++ Data Member Alignment and Array Packing

During a code review I've come across some code that defines a simple structure as follows: class foo { unsigned char a; unsigned char b; unsigned char c; } Elsewhere, an array of these objects is defined: foo listOfFoos[SOME_NUM]; Later, the structures are raw-copied into a buffer: memcpy(pBuff,listOfFoos,3*SOME_NUM); ...

Polished UI Desktop Application, which UI library to choose?

I am a long time MFC programmer and know it quite well. Recently we are planning for a large desktop application. In order to beat competition, one requirement is polished UI. We narrow down the choices to three: WinForms MFC QT4 We looked at some big WinForms applications, such as Paint.Net, and feel that it still lacks power of pe...

Boost Serializing of Object containing Map (with object values) and Multimap (with std::string values): what is needed?

See below a main() and two very simple classes. Then per Boost serialization (and what is shown) my questions are: 1) Does class B need the normal overloaded stream insertion operators '<<' and '>>' to be defined? Currently in my real code it doesn't have these. 2) Does class A in the store() and load() methods need to iterate thro...

Retrieve main class/jar file name passed to the JVM

As a C++ app, is there a way to query a java process(java.exe/javaw.exe) to retrieve the main class or jar file name that was passed to the JVM? I want the same result as when you run "jps -l": C:\>jps -l -V 2644 sun.tools.jps.Jps 4340 net.sourceforge.squirrel_sql.client.Main I think I could get the command line parameter and try to p...