views:

727

answers:

9

For every stl container there is a MFC container available in visual c++.Which is better than the other one in what sense and what do you use?

I always use STL container is that wrong?

+10  A: 

I would always prefer the STL containers because of the portability.

MFC containers will nearly never be available on Linux.

Even if you don't plan to use you're code on Linux...you never know what the future brings.

rstevens
YAGNI. If you're coding an MFC application you're not writing a portable app.
Aidan Ryan
But maybe you write some non-UI classes to support you're app. And maybe you will re-use them later on in another project that is not using MFC and should also run on Linux.
rstevens
+2  A: 

The STL ones. Seriously.

milan1612
Why? ......................
Aidan Ryan
That should be obvious, portability, defined in an industry standard, available on every implementation (that is standard compatible) etc etc...
milan1612
+9  A: 

People have pointed out portability of code as a reason to use STL, but there is a much better reason and one which is more in your self interest: Portability of skills and experience. In my opinion when you go looking for your next job having experience with STL on your resume will give you more opportunities. Why? STL effectively is part of standard C++ and if I was hiring I would assume that someone who knows STL could pick up the MFC containers fairly quickly, but I wouldn't necessarily make the opposite assumption if I was looking for someone with STL skills.

Robert S. Barnes
Yep - stl is just better anyway. I HATED the mfc containers with a passion.
Tim
+3  A: 

Preffer portability and freedom to proprietarism. Go for STL & Boost (www.boost.org).

A: 

Even when they show you numbers that MFC containers are faster, can be exception-free and make free double-espresso: just close your eyes and use the DEL key (aka NO-LOCK-IN key).

You can do all that and more portably and in plugabble ways prop solutions can only dream of. STL all the way..

rama-jka toti
A: 

Can the MFC containers be used with standard algorithms in the STL?

Martin York
Some of them, basically the Arrays (CArray<T>, C*Array). The rest of the containers do have iterators, but not with an STL-style interface, although you could write wrappers.
Logan Capaldo
+4  A: 

MFC collection classes do have some advantages if you are working within confines of MFC land. E.g. you get things like serialization (if your container elements inherit from CObject or similar) and some debugging support for "free". MSDN has a breakdown of how to choose between different MFC collection types here.

As a default though, I would lean towards the STL classes.

Logan Capaldo
what does it mean by dumped? mentioned in the url you are refering
yesraaj
It's basically a debug pretty print.
Logan Capaldo
oh thanks......
yesraaj
+4  A: 

From the source:

"And frankly the team will give you the same answer. The MFC collection classes are only there for backwards compatibility. C++ has a standard for collection classes and that is the Standards C++ Library. There is no technical drawback for using any of the standard library in an MFC application.

We do not plan on making significant changes in this area.

Ronald Laeremans Acting Product Unit Manager Vsual C++ Team "

Nemanja Trifunovic
+1  A: 

I use STL containers for many reasons: they're well tested, well documented, and well understood by people all over. They're also constantly being improved: look at all the new functionality added by Boost, and it's all backwards compatible. And if you really want to bend your mind, read Alexandrescu's Modern C++ Design: Generic Programming and Design Patterns Applied. Use of Boost and the STL is required to employ many of his techniques.

Something else to consider is the STL is "Standard" but the MFC is only "Microsoft". Any random generic C++ coder will likely understand STL, but only an old Microsoft coder will know MFC. Besides, Microsoft has pretty much abandoned MFC.

John Deters