c++

C++ ">>" and "<<" IO in C# ?

Is there a C# library that provides the functionality of ">>" and "<<" for IO in C++? It was really convenient for console apps. Granted not a lot of console apps are in C#, but some of us use it for them. I know about Console.Read[Line]|Write[Line] and Streams|FileStream|StreamReader|StreamWriter thats not part of the question. I dont...

Are there delimiter bytes for UTF8 characters?

If I have a byte array that contains UTF8 content, how would I go about parsing it? Are there delimiter bytes that I can split off to get each character? ...

Pimpl idiom used with a class member variable

Whats the correct way of implementing this class? //Header #include <boost/shared_ptr.hh> class MyClass { public: static foo() static foobar(); private: class pimpl; static boost::shared_ptr<pimpl> m_handle; static bool initialized; }; //source namespace { bool init() { //... // init() can't access...

Thread-safe variables in Linux programming

I am writing a shared library that will allow linked applications to query a resource. The resource class is implemented with only static methods (see below). It also uses a global object (well scoped in an anonymous namespace). The reason for the global variable is that I do not want to expose users of the library to the internals of t...

what is the difference between function declaration and signature?

In C or C++ what is the difference between function declaration and function signature? I know something of function declaration but function signature is totally new to me. What is the point of having the concept of function signature? What are the two concepts used for actually? Thanks! ...

How do you declare and use an overloaded pool operator delete?

I would like to know how to adapt section 11.14 of the C++-FAQ-lite to arrays. Basically, I would want something like this: class Pool { public: void* allocate(size_t size) {...} void deallocate(void* p, size_t size) {...} }; void* operator new[](size_t size, Pool& pool) { return pool.allocate(size); } void operator delete[](void*...

help with set & map on STL for c++

I am taking a CS class, and most of the assignments were in java. in the last java assignment we learned collections. This assignment we are using c++ and i need to learn the STL The required book is all in java. We were given this webpage http://www.cplusplus.com/ however, that and google is not going to get me through the assignment. ...

load XML from variable, not File

Hello, I'm trying to parse XML data stored in a variable, not a file. The reason for this is that program x replies to program y in XML, so it would seem to be best to directly parse the XML from the variable. So far I have tried to do this in TinyXML, but I don't see an interface to load from a variable. It's basically the opposite ...

debugging information cannot be found or does not match visual studio's

I copied an existing project and renamed the folder. Now I get this error when I try to compile the application debugging information cannot be found or does not match. No symbols loaded. Do you want to continue debugging ? If I click yes, it compiles and runs fine. But now I have to deal with that message. Just curious about what i...

dylib on Snow Leopard "file is not of required architecure"

I have compiled opencv on snow leopard and it says it compiled correctly, however when I try to compile my sample program against it, I get output like: g++ -o tm_scons template.o -L/opencv/opencv/build/lib -lcxcore -lcv -lcvaux -lhighgui -lml ld: warning: in /opencv/opencv/build/lib/libcxcore.dylib, file is not of required architecture...

How to make a console program doesn't have console window.

I'm writing a console program. The program doesn't print anything. So, it doesn't need to a console window. I tried to call FreeConsole() function at program starting point. When I execute the program from windows explorer, a console window appears and then disappears. But I wish the console window never appears. How can I do that?...

Making (threaded) game server in C++/WinSock

I have a game I am working on in C++ and OpenGL. I have made a threaded server that right now accepts clients (the game) and receives messages from them. Right now the game only sends messages. I want both the game and server to be able to send and receive, but I'm not sure the best way to go about it. I was considering using a thread fo...

Doxygen alternative for C++

While doxygen seems to be good at indexing a large C++ project, I have some major gripes with it. The generated output is ugly and poorly organized. Just finding a function in doxygen websites is generally a pain. Slow turnaround on finding markup errors. i.e. I have to index my whole project to find I used the wrong syntax on some fun...

How is a reference different from a pointer in implementation?

Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading about the book "Inside the C++ Object Model" by Stanley Lippman. What puzzles me is the difference between a "reference" of an object and a "pointer" to an object. I know that a reference must be initialized when declared, while ...

C++ Copy constructor, temporaries and copy semantics

For this program #include <iostream> using std::cout; struct C { C() { cout << "Default C called!\n"; } C(const C &rhs) { cout << "CC called!\n"; } }; const C f() { cout << "Entered f()!\n"; return C(); } int main() { C a = f(); C b = a; return 0; } the output I get is: Entered f()! Default C called! ...

How about defining a class but not make any instance of it?

I am learning some COM code and the following code puzzled me. STDMETHODIMP _(ULONG) ComCar::Release() { if(--m_refCount==0) { delete this; // how could this "suicide" deletion be possible? return 0; } return m_refCount; } Yes. this is the similar code from here. And there I...

Accessing member variables through boost lambda placeholder

I'm trying to print the second member variable of all items in an stl map using a lambda expression map<int, int> theMap; for_each(theMap.begin(), theMap.end(), cout << bind(&pair<int, int>::second, _1) << constant(" ")); but this is not compiling. I essentially want to de-reference the placeholder. Any idea what I'm missing...

How to ignore false positive memory leaks from _CrtDumpMemoryLeaks?

It seems whenever there are static objects, _CrtDumpMemoryLeaks returns a false positive claiming it is leaking memory. I know this is because they do not get destroyed until after the main() (or WinMain) function. But is there any way of avoiding this? I use VS2008. ...

Non-recursive mutex ownership

I read this somewhere in SO: "recursive mutex has a sense of ownership, the thread that grabs the mutex must be the same thread that releases the mutex. For non-recursive mutexes, there is no sense of ownership and any thread can release the mutex no matter which thread originally locked the mutex." I'm confused by the last statement. C...

Unsigned modulos: alternative approach?

I'm in a need to optimize this really tiny, but pesky function. unsigned umod(int a, unsigned b) { while(a < 0) a += b; return a % b; } Before you cry out "You don't need to optimize it", please keep in mind that this function is called 50% of the entire program lifetime, as it's being called 21495808 times for the sm...