Is cppreference the goto site for c++ docs? |
cppreference was created to be an online and more convenient version of the C and C++ standards.
It is primarily for experienced programmers, it is not a site that someone can learn C++ without prior experience. It is a reference, not a tutorial.
The cplusplus reference section, while good, is very outdated. No C++14/17/20 changes.
If you were to look at the
std::random_shuffle
page here you would never know it was deprecated in C++14 and removed entirely from C++17's
<algorithm>
header.
Initializer lists can be useful for cleaner, more compact code when the elements of a container are already available at creation. Your lines 12-20 could be rewritten as:
std::vector<std::string> list = { "1", "2", "3", "4", "5", "6" };
Range-based
for
loops can be helpful when accessing a container's elements. Your
display()
function could be rewritten as:
20 21 22 23 24 25 26 27
|
void display(std::vector<std::string> vec)
{
for (auto iter : vec)
{
std::cout << iter << ", ";
}
std::cout << '\n';
}
|
A range-based
for
loop will never access elements that are out of bounds. A very big plus IMO for using them.
http://en.cppreference.com/w/cpp/language/range-for