c++

C++ - String input with a pointer-to-structure?

How do you use a pointer-to-struct to get input that will be stored in a string variable? I thought simply passing pz->szCompany to getline() would behave the same as if I had used the . operator on a normal instance of Pizza (instead of a pointer-to), but when I run this program it skips over the company name prompt completely. // Part...

Ways to accidentally create temporary objects in C++?

Years ago I believed that C was absolutely pure compared to C++ because the compiler couldn't generate any code that you couldn't predict. I now believe counter examples include the volatile keyword and memory barriers (in multiprocessor programming or device drivers for memory-mapped hardware devices, where plain assembly language woul...

Why the compiler is not compiling a line in C++ Builder?

Hi boys: I was programming an application in C++ Builder 6, and I had encountered this rare problem: void RotateDice() { Graphics::TBitmap *MYbitmap = new Graphics::TBitmap(); Randomize(); int rn = random(6) + 1; switch (rn) { case 1: { //... break; } //... Some cases... } ShowDice(); ...

Absolute positioning in printout with cout in C++ ?

How do you get "absolutely positioned" columns with cout, that leftaligns text and right-aligns numbers? #include <iostream> #include <iomanip> using namespace std; struct Human { char name[20]; char name2[20]; char name3[20]; double pts; }; int main() { int i; Human myHumen[3] = { {"Mr", "Alan", "Turin...

vector size_type and encapsulation

I have a class with a private data member of type vector< A*>. The class has two public methods that actually use vector::size_type: Method returning number of elements in the vector Method returning element in the vector by index I can add to public section of the class the following typedef: typedef vector::size_type SIZE_t; ...

Best C++ Matrix Library for sparse unitary matrices

Hello, I am looking for a good (in the best case actively maintained) C++ matrix library. Thereby it should be templated, because I want to use a complex of rationals as numerical type. The matrices what I am dealing with are mainly sparse and unitary. Can you please suggest libraries and also give a small explaination why to use them, ...

c++ templates error

#include <iostream> #include <cstring> #include <string> template <typename T> inline T const& max (T const& a, T const& b) { return a < b ? b : a; } inline char const* max (char const* a, char const* b) { return std::strcmp(a,b) < 0 ? b : a; } template <typename T> inline T const& max (T const& a, T const& b, T const& ...

Using Java JAR libraries with C++

Hi, I'm developing a win32 C++ application that needs to export data to excel spreadsheets. There isn't a mature C++ library for this, but exists for Java. How I can integrate a C++ application with Java code, in such way that I can call Java functions from my C++ application? ...

WriteFile with DLLs

Hey, Im writing a DLL and I want to write some data to a file (150k+) The problem is - WriteFile is not writing everything it should write It looks like the thread gets terminated before WriteFile finish its work. any ideas ? thanks ...

Boost Preprocessor library for generating a set of types based on a list of basic types e.g. PointI32, PointF32 etc. in C++/CLI

Hi, I am trying to figure out how to use the Boost.Preprocessor library http://www.boost.org/doc/libs/release/libs/preprocessor to unfold a "generic" type for different specific types. Below I will ask this for a simple point class example. Given: struct Point##TYPE_SUFFIX_NAME { TYPE X; TYPE Y; // Other code }; I want to...

What does the "incomplete type is not allowed" error mean?

I am trying to declare a callback routine in C++ as follows: void register_rename (int (*function) (const char *current, const char *new)); /*------------------------------------------------------------*/ /* WHEN: The callback is called once each time a file is received and * accepted. (Renames the temporary file to it...

gcc compiling invalid C code

Some of my C programs are not working as expected. For example, pass by reference is not possible in C, but when I write a C program which uses that and compile it with gcc it works fine. Is gcc a C++ compiler? How do I make it behave like a C compiler? ...

Overloading global swap for user-defined type

The C++ standard prohibits declaring types or defining anything in namespace std, but it does allow you to specialize standard STL templates for user-defined types. Usually, when I want to specialize std::swap for my own custom templated type, I just do: namespace std { template <class T> void swap(MyType<T>& t1, MyType<T>& t2) {...

Why does compiling in -O2 crash my application but -O2 -fno-default-inline does not?

I have a 3rd party lib called TheLib and my lib called MyLib TheLib is compiled first with a Struct contained in a header file called variantmap.h. This header contains 2 inline functions: struct VariantMap { string name; map<string, Variant> children; bool isArray; VariantMap(VariantMap & variantMap) { name =...

Using C++\C# .Net assemblies\DLL's in win32 C++ (unmanaged) application

There is any way to use C++\C# .Net assemblies\DLL's in win32 C++ (unmanaged) applications? ...

fwrite with structs containing an array

How do I fwrite a struct containing an array #include <iostream> #include <cstdio> typedef struct { int ref; double* ary; } refAry; void fillit(double *a,int len){ for (int i=0;i<len;i++) a[i]=i; } int main(){ refAry a; a.ref =10; a.ary = new double[10]; fillit(a.ary,10); FILE *of; if(NULL==(of=fopen("test.bin","w"...

Using a singleton to store global application parameters

Hi, i'm developing a simple simulation with OpenGL and this simulation has some global constants that are changed by the user during the simulation execution. I would like to know if the Singleton design pattern is the best way to work as a temporary, execution time, "configuration repository" ...

Formatting a hard disk in c++ on Windows 7

I am wondering how to format a hard disk in Windows 7 through c++? I currently have an application that is successful at this using a function in a dll. Unfortunately I don't have the code for the dll so there is no way for me to see what its doing. It doesn't actually format the drive itself but it launches the format utility built into...

Defining a C++ type in C#

I have a .DLL and a .h file. I'm using c#, but the .DLL is written in C++. I have to problem with calling certain function within the .DLL. The problem comes when I need to call functions that have types defined in them . For example include with the .DLL was a .h file and it has a type defined like follows: struct device_info { HANDL...

stl insertion iterators

Maybe I am missing something completely obvious, but I can't figure out why one would use back_inserter/front_inserter/inserter, instead of just providing the appropriate iterator from the container interface. And thats my question. ...