c++

Size of a FILE ADDRESS in c++

How does one determine the sizeof a pos_type or offset_type such as is used in c++ stream i/o. You can't just write sizeof(pos_type) or sizeof(basic_streambuf::pos_type) because it is defined somehow inside a template that ... well, it's pretty complex. It would be nice to know this at compile time. BTW, there is a type called "stream...

How to find the length of an LPCSTR

I'm trying to convert an LPCSTR to an integer using atoi(), and to verify that the conversion occurred successfully I want to count the number of digits in the integer it produced and the original LPCSTR (it should contain nothing but integers) I'm having a hard time finding a good way to calculate the length of the LPCSTR. So far the ...

memorystream - stringstream, string, others?

hello, i am reading in a binary file via the usual c++/STL/iostream syntax. i am copying the whole content into an dynamically allocated char array and this works fine so far. but since i want to serve parts of the content as lines to another part of the program, i think it would be better/easier to stick to streams because i don't wan...

Faster way to multiply floats

Hi, We can do left shift operators in C/C++ for faster way to multiply integers with powers of 2. But we cannot use left shift operators for floats or doubles because they are represented in different way, having an exponent component and a mantissa component. My questions is that, Is there any way? Like left shift operators for int...

Making a HANDLE RAII-compliant using shared_ptr with a custom deleter

I've recently posted a general question about RAII at SO. However, I still have some implementation issues with my HANDLE example. A HANDLE is typedeffed to void * in windows.h. Therefore, the correct shared_ptr definition needs to be std::tr1::shared_ptr<void> myHandle (INVALID_HANDLE_VALUE, CloseHandle); Example 1 CreateToolhelp32...

Better method to search array?

I have an array (nodes[][]) that contains values of effective distances that looks something like this: __ __ |1 0.4 3 | |0.4 1 0 | |3 3.2 1 ... | |0.8 4 5 | |0 0 1 | -- -- Where the first value, node[0][0] is the distance from node 0 to node ...

C++ overload resolution problem

I've got the following structure: struct A { A(); virtual ~A(); virtual void Foo() =0; }; struct E; struct F; struct B: public A { B(); virtual ~B(); virtual void Bar(E*) =0; virtual void Bar(F*) =0; }; struct C: public B { C(); virtual ~C(); void Bar(E*); }; struct D: public C { ...

Best Way to Store a va_list for Later Use in C/C++

I am using a va_list to construct a string that is rendered. void Text2D::SetText(const char *szText, ...) This is all fine and good, but now the user has the ability to change the language while the application is running. I need to regenerate all the text strings and re-cache the text bitmaps after initialization. I would like to ...

C++ Vector class as a member in other class

Please I have this code which gives me many errors: //Neuron.h File #ifndef Neuron_h #define Neuron_h #include "vector" class Neuron { private: vector<double>lstWeights; public: vector<double> GetWeight(); }; #endif //Neuron.cpp File #include "Neuron.h" vector<double> Neuron::GetWeight() { return lstWeights; } Could any one tell ...

Are there any IDE's or plugins to one that will expand/preprocess a macro and show their results inline without compiling?

Are there any IDE's or plugins to one that will expand/preprocess a macro and show their results inline without compiling? I've found a couple of other questions that are related, but they require compiling. ...

How do I get a description of the current OS version in windows?

I need to get a simple description of the OS, such as "Windows XP (SP2)" or "Windows 2000 Professional" to include in some debugging code. Ideally, I'd like to simply retrieve it by calling a "GetOSDisplayName" function. Is there such a function available for C++ win32 programming? ...

Fastest implementation of one thread providing data, many threads consuming data

I have a lot of data that I want to disseminate to many different threads. This data is coming from a single thread. The consuming threads can safely access the container simultaneously. The data needs to be merged into the container ever delta seconds (50ms < delta < 1), during which time the consuming threads need to be locked out, ...

What's the recommended way of designing my public-facing API to support multiple POD types while minimizing the chance of breaking binary compatibility?

I'm currently designing a public-facing C++ API for a product which will require a precompiled binary/DLL (it will be cross-platform). I'd like for the API to allow the user to use any POD we support (where applicable), however the base requirements are maximum flexibility and binary compatibility. I'm doing something a bit similar to CP...

When do you want to use pointers vs values in C++?

I'm coming from Java and attempting to learn C++. As far as I can tell, using Pointers is very similar to how reference variables work in Java, in that you pass a memory address to the value. So I feel like I have gotten a pretty good understanding of them. I also understand that these variables are stored on the heap. However, I see ...

Compression Libraries For C++

Hello, I was reading about compression in programs and I started to create a new simple project, a zipper (just a zipper, not an unzipper), but I only found zLib, and it's for C. I know that C libraries can be used in C++, but I like to use C++ libraries. Does anyone know a good one to suggest? Best Regards. ...

VS2008: how to run two separate projects from the same solution

I have a single un-managed C++ console-app solution (.sln) with two projects (.vcproj) both are built as .exe. I want to run them both at the same time (one is a client and one is a server). How do I configure my Visual Studio such that when I hit a single button, say F5, it would be smart enough to run one after another, in the order th...

Use of "Public" in a derived class declaration?

Given this base class: class Employee { char* name; int age; public: Employee(char* name); void print(); }; With regards to the "public", what's the difference between this: class Manager : public Employee { EmployeeList employees; public: Manager(char* name, Employee* people); void print(); }...

Help interpret this stack trace

I know that it fails at strcmp. I've provided operator< below, which calls strcmp. On line #1 there's the value @0xbfffeeac. What does the @ mean? #0 0x00212bd8 in strcmp () from /lib/libc.so.6 #1 0x0012ed2f in Json::Value::CZString::operator< (this=0x8317300, other=@0xbfffeeac) at src/lib_json/json_value.cpp:221 #2 0x001361b0 ...

C++ builder 6 and codegear's C++ builder 2009 compatibility

Hello, I am required to support some software codes that were developed using C++ builder 6, and the current development environment is Codegear's C++ builder 2009. I wonder if the codegear's C++ builder 2009 is backward compatible with C++ Builder 6? Any answer is appreciated. Thanks in advance. David. ...

C++ static constant string (class member)

Hi guys. I'd like to have a private static constant for a class (in this case a shape-factory). I'd like to have something of the sort. class A { private: static const string RECTANGLE = "rectangle"; } Unfortunately I get all sorts of error from the C++ (g++) compiler, such as: ISO C++ forbids initialization of member ...