C++ facilities

Hello all,

What are most common C++ containers and std::algorithm facilities (functions, operations, etc) that a C++ programmer needs to be familiar with for programs, in your points of view, please?


And what up-to-date resource do you suggest that explains them in a simple language that can be understood well, please?

Thanks so much in advance.



By a long way, std::vector

Here is a good list of books to help you understand the language:

https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

@Repeater:
Do you think the only common C++ container is std::vector?
How about std::algorithm functions and operations, please?

@jlb: A book can't be very suitable for now since my time is limited.
std::vector is by far the most commonly used standard container.

Once you've got things in a vector, you commonly need to do something either to each one individually, so look at std::transform , or you need to come up with some final value based on all of them, so look at std::accumulate
Do you think the only common C++ container is std::vector?

No, but it should be the first choice, any other choice should be made after profiling to see if there is a problem. Oh and let's not forget about the other high use container, std::string.

How about std::algorithm functions and operations, please?

What about them? It really depends on what you're trying to accomplish. The std::algorithm is not the end all of algorithms, but there are many useful things available depending on what you're trying to accomplish.

A book can't be very suitable for now since my time is limited.

Then I really suggest you make time. A book is probably the best place to start.
Whether learning C/C++ from books -- plural, more than one or a dozen -- or from a reference/tutorial website it will take time. LOTS of time.

Generally easy to understand written in simple to understand words because it is a tutorial website: http://www.learncpp.com/

Learn C++, unlike the tutorial here, is being updated on a frequent basis. It is IMO one of the best C++ tutorial sites available on the interwebz.

The best reference site: http://en.cppreference.com/w/

cppreference is NOT a tutorial site. It doesn't hold your hand, it expects you to have a very good grasp of the language and programming concepts when poking around.

cppreference is THE up-to-date online resource for what C and C++ have to offer.

Learn C++ is a good novel, cppreference is the dictionary.
How about std::algorithm functions and operations, please?

Well, you might argue that std::string is a container, and extremely common. It isn't a generic container, so it depends on what it is you really are asking at that point.

algorithms.... sort may be the #1 vector function. find() and its cousins are used a ton. copy, swap, remove, erase are right on up there. Maybe min /max?

But that is industry wide. Think about it.
what do you do with data, really?
- you store it (the vector itself, usually)
- then you process it (loop/ transform, sort, etc)
- then you add more, remove some, or fetch some (eg user asks for a 'record' to read, modify, remove, or put in a new one...)

the above are going to dominate the industry. Countless programs do that kind of stuff, and that use case overwhelms what else may be done with the tools. It has nothing to do with C++ but the nature of what programs do and what tasks people do most often.
Last edited on
It's hard to argue that vector and string aren't popular, but to a large degree, the "most common" containers and algorithms depend on the type of programming that you do. A good approach is to be sure that you're aware of what containers and algorithms are available, even if it's just vaguely. That way when you need something, you'll think "hey, isn't there a binary search function in <algorithm>?" or "I need a heap. I think C++ has a heap." Then you can go look at the reference material.
^^^ So much this.

Algorithm and the c++ high level tools (not all of them are in algorithm) are massive and you should try very hard to not hand-write things that are in there. I think everyone probably forgets and hand-writes something now and then on some of the outliers, but make it a goal to look before you code to see if what you need, or part of what you need is already in the language. Swap is a good example: it so easy to write and if distracted, you may just stuff the 3 lines in your algorithm without remembering there is a language one.

So rather than try to get a 'most used' sample, read an overview page a few times and keep a reference handy when coding to double check. I can't remember all the stuff, few can, so just check it rather than memorize.
Thanks so much all guys. I got it. I appreciate your time and help.
Registered users can post here. Sign in or register to post.