c++

Dealing with char buffers.

As a C++ programmer I sometimes need deal with memory buffers using techniques from C. For example: char buffer[512]; sprintf(buffer, "Hello %s!", userName.c_str()); Or in Windows: TCHAR buffer[MAX_PATH+1]; // edit: +1 added ::GetCurrentDirectory(sizeof(buffer)/sizeof(TCHAR), &buffer[0]); The above sample is how I usually create lo...

C++: ofstream doesn't flush

I have the following code, running on Suse 10.1 / G++ 4.1.0, and it doesn't write to the file: #include <fstream> #include <iostream> int main(){ std::ofstream file("file.out"); file << "Hello world"; } The file is correctly created and opened, but is empty. If I change the code to: #include <fstream> #include <iostream> in...

Converting an uint64 to string in C++

What's the easiest way to convert an uint64 value into a standart C++ string? I checked out the assign methods from the string and could find no one that accepts an uint64 (8 bytes) as argument. How can I do this? Thanks Nelson R. Pérez ...

How could one implement C++ virtual functions in C

Possible Duplicate: Object oriented programming in C The C++ language provides virtual functions. Within the constraints of a pure C language implementation, how can a similar effect be achieved? ...

Deleting user-defined vectors - C++

Hi, I have 2 classes, say A & B. Class B has a destructor of its own. Within class A, I have a vector of pointers to objects of class B. The vector is as follows: vector<B*> vect; In the destructor for class A, how do I retrieve memory? If I cycle through the vector, do I retrieve each object and use delete on every retrieved object?...

header files. class and aplication of stacks

when i put the header file in the same folder of the source code. the program doesnt compile. it shows errors. like:7 E:\data structure\asig 5\code.cpp `Queue' has not been declared driver for queue adt. code.cpp #include <iostream> #include "QueueLnk.h" using namespace std; // ********************* Function Prototypes **************...

The python exception vs C++ exception handling

With the following code, I get the "Gotcha!" with python. try: x = 0 y = 3/x except Exception: # ZeroDivisionError print "Gotcha!" I think this is the equivalent C++ code, but it can't catch the exeption. #include <iostream> int main() { int x = 0; //float y = 3.0/x; int z = 0; try { z = 3 / x; } ca...

How can I know the name of the exception in C++?

With Python, I could get the name of the exception easily as follows. run the code, i.e. x = 3/0 to get the exception from python "ZeroDivisionError: integer division or modulo by zero" tells me this is ZeroDivisionError Modify the code i.e. try: x=3/0 except ZeroDivisionError: DO something Is there any similar way to find the except...

Question about rvalue in C++0x

I create many times I use class DataBuffer in many places in code, so it should be fast and lightweight. Moreover I use various buffer sizes, so to reduce memory allocations I wrote such template: template<unsigned int T_buffer_size> class DataBuffer { public: DataBuffer (const unsigned int &buffer_size); char buffe...

Programmatically make a Header item 'hot' or 'selected'

I'm using a Win32 Header. I want to make it so that the header item I click on stays 'selected' or looks selected until I press another one. I want to avoid disabling it for aesthetic reasons. Thanks ...

Getting strange error when attempting to convert Unmanaged C++ class to Managed C++ class (for use in .net)

Greetings, First off, I am not a C++ developer, so please forgive my shortcomings.... I am attempting to take another developer's C++ unmanaged code and re-work it so it can be called from a managed DLL from our c#.net application. Please keep in mind that I'm a .net developer, and I haven't touched C++ in like 12 years. And when I ...

How to create map with keys/values inside class body once (not each time functions from class are called)

I would like to create C++ class which would allow to return value by given key from map, and key by given value. I would like also to keep my predefined map in class content. Methods for getting value or key would be static. How to predefine map statically to prevent creating map each time I call getValue(str) function? class Mapping {...

SVNKit like wrapper for C or C++

Before I start building one myself; Is there a wrapper for C or C++ which does the same thing as SVNKit? ...

Error processing : return value vs exception in C++

In the course of asking about catching 'divide by 0' exception, I found that with C++, we can't do that. I mean, divide by 0 doesn't throw an std::exception. Some of the hints that I found were I have to check the value, and throw the exception by self. I say it's confusing, as I've thought that C++ adopted the exception idea in order...

In C/C++, are volatile variables guaranteed to have eventually consistent semantics betwen threads?

Is there any guarantee by any commonly followed standard (ISO C or C++, or any of the POSIX/SUS specifications) that a variable (perhaps marked volatile), not guarded by a mutex, that is being accessed by multiple threads will become eventually consistent if it is assigned to? To provide a specific example, consider two threads sharing ...

Is there a simple way to forward to a member function with a matching function signature?

Is there a simple way to forward to a member function with a matching function signature? typedef std::tr1::function<int(int,int,int,int)> TheFn; class C { int MemberFn(int,int,int,int) { return 0; } TheFn getFn() { //is there a simpler way to write the following line? return [this](int a,int b,int c,int d){ r...

How do I write a c++ dictionary to a Lua table?

I have some C++ code that interacts with some Lua code. Basically, I want to be able to get some results (in the form of a dictionary a.k.a a collection of items) from a query message and then push them out to Lua as a table so that I can easily access all the results from Lua by using the dictionary. Right now, I just get one specific ...

Converting COFF lib file to OMF format

Hello Is there any way to convert COFF library (lib file) to OMF library for using with C++Builder6 ? This coff is not just import library, it conatians some code. When I try to convert it using borland's coff2omf.exe, I get 1KB file from 15KB file. ...

How do I merge Valgrind memcheck reports from multiple runs of the same process?

I've got an set of acceptance tests that run nightly. I'd like to use valgrind to check for memory leaks in my code automatically as an additional safe-guard to manually checking for leaks. Updating my scripts to run my processes under valgrind is trivial, however, each test starts and stops a number of processes and there are around 1...

Can't draw triangles in OpenGL but other primitives render fine...

Good afternoon, I'm trying to learn to use a graphics library that uses OpenGL. I can draw 2D primitives (text and lines) but 3D triangles don't render. I've tried everything I can think of but as an OpenGL newcomer I've probably missed something obvious. This code is not intended to be efficient. I'm trying to get it to work first. ...