I\'m looking for practical and educational samples of C++ / STL code fitting in few lines. My actual favorites are:
Empty a vector freeing its reserved memory:<
My favorite is copying containers to the output: And copying the input stream into a container.
#include
#include
#include
#include
int main()
{
std::vector data;
std::copy(std::istream_iterator(std::cin),
std::istream_iterator(),
std::back_inserter(data)
);
std::copy(data.begin(),data.end(),
std::ostream_iterator(std::cout,"\n")
);
}