c++

Printing the contents of a file using the #include directive (preprocessor)

Hi, Say i have a file, t.txt, that contains the following two lines: one two Now, I would like to write a program which will #include that file somehow and print its contents, nothing more. That is, i want the contents of that file to appear in my code as a static text, at compile time. Any ideas? The reason im asking is this: I ...

Writing to shared memory

How can I write from a file to shared memory using the Win32 API? I have this code: hFile = CreateFile("input.map", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, TEXT("SharedObject")); lpMapAddre...

Is there a caching penalty for mixing binary data and instructions within close proximity of each other?

I'm procedurally generating 128-byte blocks with some set n-byte header reserved for machine-language functions that I'm simply calling via in-line assembly. They aren't defined anywhere and are generated at run-time into pages allocated into memory with access for execution. However, I want to reserve the end (128 - n) bytes of these ...

How do I use basic_filebuf with element type other than char?

Say I want to read the contents of a file using basic_filebuf. I have a type called boost::uintmax_t which has a size of 8 bytes. I am trying to write the following: typedef basic_filebuf<uintmax_t> file; typedef istreambuf_iterator<uintmax_t> ifile; file f; vector<uintmax_t> data, buf(2); f.open("test.txt", std::ios::in | std::ios::b...

Template Type Conversion

I'm building a matrix template. There are operators, functions and all work fine. Except when I try to convert a double type matrix to int type matrix (or vice versa). = operator cannot be defined so its not possible to override it for basic_Matrix2D and basic_Matrix2D external to class. I know I can write in class = operators to convert...

How to initialize a const field in constructor?

Imagine I have a C++ class Foo and a class Bar which has to be created with a constructor in which a Foo pointer is passed, and this pointer is meant to remain immutable in the Bar instance lifecycle. What is the correct way of doing it? In fact, I thought I could write like the code below but it does not compile.. class Foo; class ...

Waiting for a DBus service to be available in Qt

With a Qt DBus proxy built on QDbusAbstractInterface (via qdbusxml2cpp), what's the best way to handle the service/object you want to interface to not being available when you start? Note: I'm not interested in simply knowing it (you can use BlahService.isValid() to find that out); I want to be able to know if it's valid, and know when ...

Simple struct question

struct { char a; int b; } x; Why would one define a struct like that instead of just declaring it as: struct x { char a; int b; }; Thanks ...

Is there a c/c++ multi-monitor library for changing between XP's desktop setting of dualview or clone?

I am writing an application where it would be helpful to automatically switch between having Windows XP's desktop in dualview or cloned. The application uses a small wxWidgets window for the GUI. It would be nice to have a button within the GUI that could easily switch between dualview and cloned. Is there a c/c++ library that gives...

c++ - relearning

I haven't done C++ for about three years and looking to get back and ready. What is the best way? any open source projects that I might want to look at to recall all the details and be ready for interviews? I started reading (again) C++ Primer 5th edition but was wondering whether there's more efficient way since I did program in C++ for...

Using GCC through Xcode to compile basic programs

So, I'm a brand new CS student, on a Mac, and I'm learning C++ for one of my classes. And I have a dumb question about how to compile my super basic C++ program. I installed Xcode, and I'm looking through the documentation to try and figure out how to use it (and I highly suspect it's extremely overpowered for what I'm doing right now)...

Static array of const pointers to overloaded, templatized member function

Static array initialization... with const pointers... to overloaded, templatized member functions. Is there a way it can be done (C++03 standard code)? I mean, if I have the template class template <class T1, class U1, typename R1> class Some_class { public: typedef T1 T; typedef U1 U; typedef R1 R; R operator()(T pr...

Conditional operator can't resolve overloaded member function pointers

I'm having a minor issue dealing with pointers to overloaded member functions in C++. The following code compiles fine: class Foo { public: float X() const; void X(const float x); float Y() const; void Y(const float y); }; void (Foo::*func)(const float) = &Foo::X; But this doesn't compile (the compiler complains that ...

Active Accessibility (COM) calls return differently depending if caller is a thread vs. a process. What?!

I have code that uses Microsoft Active Accessbility to get information about the active window. Strangely, I can only enumerate all the controls in a window (in this case Internet Explorer) if I use a process. If I spawn a thread and call the EXACT same code, MSAA will return only a subset of controls. Usually just the menu bar and toolb...

Template Array in VC++ 2008

I am trying to open raw data file(s) that contain some numbers using VC++. The numbers could be 8/16/24 bit. I have a prior knowledge of that for a given file. Can I use C++ templates to create array variables to store numbers read from files based on what bit-depth they are? Something on the lines of this pseudo code: if(BitDepth==8) ...

C++ Timer not working?

I'm trying to make a timer in c++. I'm new to c++. I found this code snippet UINT_PTR SetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc); I put it in my global variables and it tells me Error 1 error C2373: 'SetTimer' : redefinition; different type modifiers I'm not sure what this means. Is there a more p...

Most vexing parse: why doesn't A a(()); work?

Among the many things Stack Overflow has taught me is what is known as the "most vexing parse", which is classically demonstrated with a line such as A a(B()); //declares a function While this, for most, intuitively appears to be the declaration of an object a of type A, taking a temporary B object as a constructor parameter, it's act...

Lost Focus and GotFocus in c++

How do you add code to these events for native c++. I couldnt find a WM_LOSTFOCUS OR WM_GOTFOCUS; I only found WM_SETFOCUS. I need code to happen when my window loses focus, and regains it. Thanks ...

is there any good library for printing preview in MFC ?

I need to print records in a grid view, and need to preview it before printing. I want to know whether or not there is a strong library for printing preview? And with the library I can change the position, layout of the data to print. More important: I need to change the data's layout, how can I do that? ...

Good C++ directory and file library?

Hello everyone! I am making an application in C++ for windows, and one of its prime functions has to be directory and file io (searching, creating, etc). I basically want to be able to recursively search directories, and most of all be able to get the file names in a directory. Then I want to be able to get the directory names in the cur...