c++

What is the name of this operator: "-->"?

After reading this post on comp.lang.c++.moderated, I was completely surprised that it compiled and worked in both VS 2008 and G++ 4.4. The code: #include <stdio.h> int main() { int x = 10; while( x --> 0 ) // x goes to 0 { printf("%d ", x); } } Where in the standard is this defined, and where did it come ...

Storing char array in a class and then returning it

Hi, I need to store a char array inside a class and then return it. I have to admit that I'm a bit confused about pointers and have tried everything I can think of but can't get it to work. Here's what I have: #include <iostream> using namespace std; class Test { public: void setName(char *name); char getName(); private: c...

how to implement common functor for several classes in c++

Hi, suppose you have two (or more) classes with private member vectors: class A { private: std::vector<X> priv_vec; public: //more stuff } class B { private: std::vector<Y> priv_vec; public: //more stuff } and you have a functor-class which has a state and works on a generic vector (does sorting or counts...

How to get the default value of a column of MS Access Database using C++?

This is the sql script I used to create a table in MS Access Database. CREATE TABLE Contracts ( id int NULL DEFAULT 0, sex varchar(255) DEFAULT 'female' NOT NULL ) Now I want to programmatically get the default value of the field: "sex", I know it's 'female' but I don't know how to get it using C++ ADO interface. Below is a snippet ...

How to abort getchar in a console application when closing it

I've written a simple command line tool that uses getchar to wait for a termination signal (something like: 'Press enter to stop'). I however also want to handle the SC_CLOSE case (clicking the 'close' button). I did this by using SetConsoleCtrlHandler. But how do I cancel my getchar? I tried doing fputc('\n', stdin);, but that results...

How to get boost wdirectory_iterator to return UTF32 on the Mac

directory_iterator returns UTF8 using both Visual Studio and Xcode as expected. wdirectory_iterator, however, returns UTF16 using Visual Studio, and UTF8 using Xcode, despite returning a wchar_t string. What can I change to get wdirectory_iterator to return UTF32? An answer to a question I asked previously suggests that changing the l...

null pointer equivalence to int

In "The C++ Programming Language", Bjarne writes that the null pointer is not the same as the integer zero, but instead 0 can be used as an pointer initializer for a null pointer. Does this mean that: void * voidPointer = 0; int zero = 0; int castPointer = reinterpret_cast<int>(voidPointer); assert(zero == castPointer) // this isn't nec...

Fgets in C++ repeats last line

I have program like (from link text) FILE* soubor; char buffer[100]; soubor = fopen("file","r"); string outp = ""; while (! feof(soubor)) { fgets(buffer,100,soubor); fputs (buffer , stdout); } fclose(soubor); and file like A B C D E and the output of program is A B C D E E it repeats last line of file twice. I ha...

Is there such a C++ optimisation?

E.g. vector<string> a; vector<string> b; a.push_back("first"); b=a; Would it be optimised somehow as vector<string> b; b.push_back("first"); ...

STL containers on the stack and the heap

If std::vector and friends are self resizing, does that mean if I declare a vector like so: std::vector<string> myvec; Then it'll resize using more stack, whereas: std::vector<string> *myvec = new std::vector<string>(); Would resize using more heap? ...

Design with (pure)virtual C++

Hello, First of all I have to mention that I have read many C++ virtual questions in on stackoverflow. I have some knowledge how they work, but when I start the project and try to design something I never consider/use virtual or pure virtual implementations. Maybe it is because I am lack of knowledge how do they work or I don't know ho...

How to identify more than 4 gb ram on 32-bit machine

I know that a 32-bit OS cannot see more than 4 GB of RAM. So if I were to install, say, 6 GB of RAM on a machine running 32-bit OS, is there any way to identify that? I know one way to get the installed RAM is through WMI class: win32_physicalmemory.Capacity But I don't know if it'll show the correct installed ram size rather than suppor...

typedef in template base class

I'm trying to define base class, which contains typedef's only. template<typename T> class A { public: typedef std::vector<T> Vec_t; }; template<typename T> class B : public A<T> { private: Vec_t v; // fails - Vec_t is not recognized }; Why in B I receive an error that Vec_t is not recognized and I need to write it explici...

What is this C++ technique for adding types to a class called?

I've just found some C++ code (at http://msdn.microsoft.com/en-us/library/k8336763%28VS.71%29.aspx), which uses a technique I've never seen before to add types to an existing class: class Testpm { public: void m_func1() { cout << "m_func1\n"; } int m_num; }; // Define derived types pmfn and pmd. // These types are pointers to mem...

Converting a unix time to a human readable format

I'm building my own unix time to human readable conversion, and I'm stuck. I can extract the year just fine, but the day is proving too tricky. /* Converts a 32-bit number of seconds after 01-01-1970 to a _SYSTEMTIME structure */ static _SYSTEMTIME Convert(unsigned long a_UnixTime) { newtime.wMilliseconds = 0; newtime.wYear = (un...

how to make a c/c++ program run in code blocks ide?

i want to run a c program in code blocks ide but not able install the compiler to run . How to do it ? ...

How to repeat key strokes with SendInput?

I'm writing a little tool in VC++ to record key strokes to replay them later, a macro recorder. It works quite nice already, using a keyboard hook function that reads each and every key press and release event. The playback works with the SendInput() function and generally also works fine - except for repeating key strokes. Pressing a ke...

Destruction of singleton in DLL

I’m trying to create a simple Win32 DLL. As interface between DLL and EXE I use C functions, but inside of DLL i use C++ singleton object. Following is an example of my DLL implementation: // MyDLLInterface.cpp file -------------------- #include "stdafx.h" #include <memory> #include "MyDLLInterface.h" class MySingleton { friend ...

Why no warning with "#if X" when X undefined?

I occasionally write code something like this: // file1.cpp #define DO_THIS 1 #if DO_THIS // stuff #endif During the code development I may switch the definition of DO_THIS between 0 and 1. Recently I had to rearrange my source code and copy some code from one file to another. But I found that I had made a mistake and the two par...

Detecting metadata-only read requests in windows filesystem

Hello, I'm developing a kind of filesystem driver. All of read requests that windows makes to my filesystem goes by the driver implementation. I would like to distinguish between "normal" read requests and those who want to get only the metadata from the file. ( Windows reads first 4K of the file and then stop reading ). Does Windows ...