How do I convert from stringstream to string in C++?
How do I convert from std::stringstream to std::string in C++? Do I need to call a method on the string stream? ...
How do I convert from std::stringstream to std::string in C++? Do I need to call a method on the string stream? ...
I was reading through some threading related code and found this piece of code: MyThread::start() { //Create a thread m_pThread = AfxBeginThread(/*some parameters*/) //Create a duplicate handle for the created thread m_hDuplicateHandle = DuplicateHandle(/* some more parameters*/) } MyThread::stop() { //Set some variables so ...
I'm working on win 32 multithreading with c++. Scenario: I have a function used by multiple threads. This function as a critical sections (or any kind of construct that can lock a resource). In the critical section an exception is thrown. At this point I need to take care of unlocking the resource in the exception catch block. Is there ...
Have you ever seen any library/code that overloaded boolean operators, which is said to be evil? and What advantages does it give to the user? ...
When I create a library on Linux, I use this method: Build: libhelloworld.so.1.0.0 Link: libhelloworld.so.1.0.0 libhelloworld.so Link: libhelloworld.so.1.0.0 libhelloworld.so.1 The versioning is so that if you change the public facing methods, you can build to libhelloworld.so.2.0.0 for example (and leave 1.0.0 where it is), so that ...
I found the following code in a library: class Bar { public: bool foo(int i) { return foo_(i); } private: virtual bool foo_(int i) = 0; }; Now I'm wondering: Why would you use this indirection? Could there be any reasons why the above would be better than the simple alternative: class Bar { public: virtual bool foo(int i) ...
One example could be: RAII - Resource Acquisition is Initialization used with critical sections Any others that are important, popular and you often use? ...
I stumbled upon this piece of code this seems totaly broken to me, but it does happen that "this" is null. I just don't get how this can be null it is inside a normal method call such as myObject->func(); inside MyObject::func() we have if (!this) { return false; } is there any way I can have the first line to throw a NullPointer...
I suspect that I will shortly have a need to write an "integration" library that will need to call an OLE object on Windows from Java. I have done Java to C/C++ integration on windows before (using C/C++ and JNI) - so I'm not new to that part of the equation. However; I'd like to try out writing a C/C++ wrapper around an OLE object to ...
When debugging, sometimes you need to attach an already running process instead of just starting the application in a debugger. It's common for myself to put in a Sleep() or MessageBox call, so that it's easier to attach a debugger. I worry that some of these may be committed eventually to source control. What is the best thing to do...
Hi, a theoretical question. After reading Armstrongs 'programming erlang' book I was wondering the following: It will take some time to learn Erlang. Let alone master it. It really is fundamentally different in a lot of respects. So my question: Is it possible to write 'like erlang' or with some 'erlang like framework', which given tha...
Hi, I'm running emacs 23 with c++-mode and having some indentation problems. Suppose I have this code: void foo() { if (cond) { <--- int i; ... } <--- } This seems to be the default behavior of the automatic indentation. However I'd like to change it so it'll be like this: void foo() { if (cond) { ...
When I create shared libraries, I have a header file (but with no file name extension) in the root of the library source named the same as the library. So for example, if my library was called libirock.so, then I'd have a file called irock in the project root. This file will include all of the most important headers in the library, so t...
I'm writing a program under MS Visual C++ 6.0 (yes, I know it's ancient, no there's nothing I can do to upgrade). I'm seeing some behavior that I think is really weird. I have a class with two constructors defined like this: class MyClass { public: explicit MyClass(bool bAbsolute = true, bool bLocation = false) : m_bAbsolute(bAbso...
How come I get this error when compiling with the -m32 argument? unrecognised emulation mode: 32 I'm compiling using g++ on an x86_64 machine. It happens in one project, but not the other... Any hints? Note: I'm using Eclipse CDT, so perhaps this is an IDE specific gocha? Rephrased question Perhaps a better question would be: Wh...
Hello I'm writing a little project in c++ where I would like to have some classes that does some work, I wrote the interfaces and the implementation of the classes. The thing that surprises me is that I cannot have a simple class without a main(), I would like to have a class that once instantiated, It's methods can be called, do things...
While debugging some code, I came across an array named default. I thought that keywords were not allowed as variable names. #include "stdafx.h" #include <stdio.h> int main() { int default = 5; printf("%d\n", default); return 0; } Now the above code compiles without a hitch on VS 2008. Isn't 'default' a keyword? How come it works ...
Why is callback called once only? bool callback() { static bool res = false; res = !res; return res; } int main(int argc, char* argv[]) { vector<int> x(10); bool result=false; for_each(x.begin(),x.end(),var(result)=var(result)||bind(callback)); return 0; } ...
I'd like to do this: MyClass mc = MyClass("Some string" << anotherString); Thanks for your answers, I have decided to re-write this question based on what you've told me, as it's gotten a little messy. Eventually, I read C++ format macro / inline ostringstream, and decided to use a macro, as it's not really possible to do this using a...
There is this post for .Net, but it is not really informative. Any other suggestions? This must be a duplicate, though my first cursory search only turned up the one I already mentioned. Duplicate of: Option Parsers for c/c++? Best way to parse command line arguments in C# ...