c++

How can I use Enum::GetName in unmanaged C++

I am using managed extensions in VS 2008 I want to print the name of an en enum value This code used to be fine VS 2003 Enum::GetName(__typeof(COMMAND_CODES),__box(iTmp)) but now I get a comile error here is my enum typedef enum { /* Command codes */ UMPC_NULL = 0, } COMMAND_CODES Any clues ? ; ...

Problem with file stream/fstream in Xcode C++

Here is a simple program to output to a text file: #include <iostream> #include <fstream> using namespace std; int main() { double myNumber = 42.5; fstream outfile("test.txt", fstream::out); outfile << "The answer is almost " << myNumber << endl; outfile.close(); } All that ends up being wrote to my text file is, "The answer is almo...

Using find_if on std::vector<std::string> with bind2nd and string::compare

This may seem to be an academic question, but still I would be very interested in the answer: I have a vector of strings s in which I would like to find a given string findme. This can be done using something like find(s.begin(), s.end(), findme); My question is: There must be a way doing the same using find_if and the compare method...

Any reason to replace while(condition) with for(;condition;) in C++?

Looks like while( condition ) { //do stuff } is completely equivalent to for( ; condition; ) { //do stuff } Is there any reason to use the latter instead of the former? ...

How can I see symbols of (C and C++) binary on linux?

Which tools do you guys use? How do demangle c++ symbols do be able to pass it to profiler tools, such as opannotate? Thanks ...

Qt-GUI with several "pages", how to synchronize the size of several QWidgets

I am currently writing a wizard-style application using Qt4. I am not using the wizard class however, since going next/back does not make sense from every step in the process. The user starts off at a "hub"-window with five buttons, each of which take him to another window at a different stage of the process. At the beginning all but th...

C++: tiny memory leak with std::map

I am writing a custom textfile-data parser (JSON-like) and I have lost many hours trying to find a tiny memory leak in it. I am using VC++2008 and the commands _CrtMemCheckpoint and _CrtDumpMemoryLeaks to check for memory leaks. When I parse any file and then remove it from memory (alongside any other memory claimed), I get a 16 bytes ...

const char* to TDesC16

Hi I have a const char* that specifies the file that I want to delete. I want to use RF::Delete to delete a file which takes a TDesC16 as input argument. Does anyone know how to easily convert RFs fs; TUint err; const char *pFileToDelete = "c:\\myfile.txt"; if ( fs.Connect () == KErrNone ) { err = fs.Delete(pFileToDelete); fs.Cl...

visual studio - run several applications at once

The project, I work on, consists of several executables which run in background and a frontend. I develop in Visual Studio 2005. Often I need to run one background app with breakpoints enabled and then control it from the frontend. I set the important background app as a startup project and press F5. Then I start the frontend and the oth...

How can I use std::for_each with boost::bimap?

I have a boost::bimap and I want to iterate over all positions to add the values of the given side to another STL-compatible container. How can I do this? My approach was to use std::for_each together with boost::bind: std::for_each(mybimap.left.begin(), mybimap.left.end(), boost::bind(&vector::push_back, &m...

trick question regarding declaration syntax in C++

Have a look here: In the following code, what would be the type of b? struct A { A (int i) {} }; struct B { B (A a) {} }; int main () { int i = 1; B b(A(i)); // what would be the type of b return 0; } I'll appreciate it if anybody could explain to me thoroughly why would such syntax exist :) Thanks. ...

Qt doesn't find QStackedWidgets' slot setCurrentWidget

I am writing a wizard-style application in Qt that uses a QStackedWidget to organize the individual pages of the wizard. Now I want to switch between the pages, which should be possible using the function setCurrentWidget(...): I have a simple main class that instantiates a QWidget audioconfig. Then, it adds this QWidget to a QStackedWi...

Can you evaluate a constructor call to boolean with an overloaded bool()?

Can a constructor call be evaluated to a boolean if the bool() operator is overloaded? class A { public: A() {}; operator bool() const { return true; } } main() { if (A a = A()) { // do stuff } } Is the above code valid, or do I need to implement main like: int main(int argc, const char* argv[]) { A a(); if (a) { /...

XML Serialization/Deserialization in C++

I am using C++ from Mingw, which is the windows version of GNC C++. What I want to do is: serialize C++ object into an XML file and deserialize object from XML file on the fly. I check TinyXML. It's pretty useful, and (please correct me if I misunderstand it) it basically add all the nodes during processing, and finally put them into a...

Calling timeconsuming functions from a constructor

What I'm looking right now is a set of classes derived from a common base class. Most, but not all, of the classes require some input parameters which are obtained through modal dialogs. Those dialogs are set up and executed in the constructor of the classes. As long as the dialog isn't finished, the object isn't constructed completely. ...

What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?

It seems that many projects slowly come upon a need to do matrix math, and fall into the trap of first building some vector classes and slowly adding in functionality until they get caught building a half-assed custom linear algebra library, and depending on it. I'd like to avoid that while not building in a dependence on some tangenti...

Sorting a vector of custom objects

How does one go about sorting a vector containing custom (i.e. user defined) objects. Probably, standard STL algorithm sort along with a predicate (a function or a function object) which would operate on one of the fields (as a key for sorting) in the custom object should be used. Am I on the right track? ...

Can I use an stl map if I plan to use arbitrary class objects as the key?

I'm new to STL. The thing stumping me about using a map to store arbitrary objects: std::map<MyClassObj, MyDataObject> MyMap; is how I find objects. How would MyMap.find (MyClassObjInstance) work for instance? Do I need to implement my own iterator and provide some standard functions which would include some equivalence function? A...

map of vectors in STL?

I want to have a map of vectors, (but I don't want to use pointer for the internal vector), is it possible? // define my map of vector map<int, vector<MyClass> > map; // insert an empty vector for key 10. # Compile Error map.insert(pair<int, vector<MyClass> >(10, vector<MyClass>)); I know that if I have used pointer for vector, as fo...

Why do you need to append an L or F after a value assigned to a C++ constant?

I have looked at quite a few places online and can't seem to find a good explanation as to why we should append an F or L after a value assigned to a C++ constant. For example: const long double MYCONSTANT = 3.0000000L; Can anyone explain why that is necessary? Doesn't the type declaration imply the value assigned to MYCONSTANT is a l...