c++

Sleep function in C++

Hello, I need a function like Sleep(time); that pauses the program for X milliseconds, but in C++. Please write which header to add and the function's signature. Thank you! ...

How do I configure indentation in vim in a specific way?

If I type the following void main(int blah, and then press enter, I want to continue here: float blah); How can I achieve this? ...

Moving Qt UI code out to separate class

I'm just starting with Qt. Despite spending sometime on it this evening, I'm struggling to move my UI setup code out of main into it's own class. #include <QtGui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *window = new QWidget; QLabel *hw = new QLabel(QObject::tr("Hello World!")); QHBox...

C++ operator[] syntax.

Just a quick syntax question. I'm writing a map class (for school). If I define the following operator overload: template<typename Key, typename Val> class Map {... Val* operator[](Key k); What happens when a user writes: Map<int,int> myMap; map[10] = 3; Doing something like that will only overwrite a temporary copy of the [null]...

C++ deque's iterator invalidated after push_front()

Hello all! Just now, I'm reading Josuttis' STL book. As far as I know -- c++ vector is a c-array that can be reallocated. So, I understand, why after push_back() all iterators and references can become invalid. But my question is about std::deque. As I know it is array of large blocks (c-array of c-arrays). So push_front() inserts elem...

Please help in understanding how the pointer referencing works

I am currently reading "Developer's Workshop to COM and ATL 3.0". Chapter 3 introduces GUIDs, referencing and comparisons. Pointers are painful. I could use some help in deciphering the REFGUID #define (see below) and how memcmp in IsEqualGUID works against the pointers. Given: typedef struct_GUID{ unsigned long Data1; u...

PInvoke on the Windows Mobile platform

So I'm trying to invoke a function I have in my unmanaged C++ dll. void foo(char* in_file, char * out_file) In my C# application I declare the same function as [DllImport("dll.dll")] public static extern void foo(byte[] in_file, byte[] out_file); The actual parameters I pass through an ASCII encoder like so byte[] param1 = Encodi...

Why is it preferable to write func( const Class &value )?

Why would one use func( const Class &value ) rather than just func( Class value )? Surely modern compilers will do the most efficient thing using either syntax. Is this still necessary or just a hold over from the days of non-optimizing compilers? Just to add, gcc will produce similar assembler code output for either syntax. Perhaps...

I have a floating-point overflow problem

Well, I'm a beginner, it's my year as a computer science major. I'm trying to do an exercise from my textbook that has me use a struct called MovieData that has a constructor that allows me to initialize the member variables when the MovieData struct is created. Here's what my code looks like: #include <iostream> #include <iomanip> #i...

python executing existent (&big) c++ code

I have a program in C++ that uses the cryptopp library to decrypt/encrypt messages. It offers two interface methods encrypt & decrypt that receive a string and operate on it through cryptopp methods. Is there some way to use both methods in Python without manually wrapping all the cryptopp & files included? Example: import cppEncrypt...

32-bit to 16-bit Floating Point Conversion

I need a cross-platform library/algorithm that will convert between 32-bit and 16-bit floating point numbers. I don't need to perform math with the 16-bit numbers; I just need to decrease the size of the 32-bit floats so they can be sent over the network. I am working in C++. I understand how much precision I would be losing, but that...

am trying to create class to encapsulate toolbar but the background turns black. c++ win32api

i created a simple class to hide the details of creating a toolbar in win32 api but i dont like the toolbars it is producing. (See image for clarification. I dont have reputation points so i have just posted a link) http://i35.tinypic.com/1zmfeip.jpg I have no idea now the black background is coming into my application. Here is the cl...

Getting error while linking an OCCI program on AIX

Hi All , I have written one sample program for connecting Oracle in C++ using OCCI.. It is giving me a runtime error . ld: 0711-317 ERROR: Undefined symbol: .oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode,void*,void*(*)(void*,unsigned long),void*(*)(void*,void*,unsigned long),void(*)(void*,void*)) ...

Array PopFront Method C++

Trying not to lose it here. As you can see below I have assigned intFrontPtr to point to the first cell in the array. And intBackPtr to point to the last cell in the array...: bool quack::popFront(int& nPopFront) { nPopFront = items[top+1].n; if ( count >= maxSize ) return false; else { items[0].n = nPopFront; ...

Useful things to put in the user stream segment of minidumps

I am interested in what useful things developers put in the user stream data structure that can be embedded in minidumps. MSDN describes the parameter for MiniDumpWriteDump as such: PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam and describes the parameter thusly: UserStreamParam [in] Pointer to an array of MINIDUMP_USER_STREAM_...

Expected contructor, destructor, or type conversion before '<' token

From what I can gather from Google, I must have syntax/parsing error but I can't seem to locate it.. This is my header file: #include <fstream> #include <iostream> #include <vector> #ifndef DATA_H #define DATA_H #include "Data.h" #endif vector<Data*> DataReader(); // This is line 11, where the error is.. And this is the .cpp fil...

Shared string in C++ ?

Which "shared string" implementation for C++ would you recommend? (Sorry if I missed a similar question. I had a look but could not find any) ...

C++ How to find the biggest key in a std::map?

At the moment my solution is to iterate through the map to solve this. I see there is a upper_bound method which can make this loop faster, but is there a quicker or more succinct way? ...

Stream and c++ - parsing file

Hello, I did it before... But I forgot. I have a file with some data: 0.5 0.6 0.7 1.2 1.5 How can I read this in c++? I did it with stream... something like: float var = 0; stream >> var; ...

How can I debug St9bad_alloc failures in gdb in C?

I have a program failing with: terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc I imagine it's something to do with malloc/free, but I don't know which one. What breakpoint can I in gdb set that will break on the error so that I can view a stack trace? The program is a combination of C and C++,...